Changeset 623c16a for src/tests/concurrent/examples/boundedBufferEXT.c
- Timestamp:
- May 2, 2018, 4:18:37 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 68e9ace
- Parents:
- 6d539f83
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/boundedBufferEXT.c
r6d539f83 r623c16a 8 8 // Created On : Wed Apr 18 22:52:12 2018 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Fri Apr 20 22:25:14201811 // Update Count : 610 // Last Modified On : Wed May 2 16:12:58 2018 11 // Update Count : 7 12 12 // 13 13 … … 22 22 enum { BufferSize = 50 }; 23 23 24 forall( otype T ) 25 monitor Buffer {26 int front, back, count;27 T elements[BufferSize];28 }; 24 forall( otype T ) { 25 monitor Buffer { 26 int front, back, count; 27 T elements[BufferSize]; 28 }; // Buffer 29 29 30 forall( otype T ) 31 void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; } 30 void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; } 32 31 33 forall( otype T ) 34 int query( Buffer(T) & buffer ) { return buffer.count; } 32 int query( Buffer(T) & buffer ) { return buffer.count; } // read-only, no mutual exclusion 35 33 36 forall( otype T ) // forward 37 T remove( Buffer(T) & mutex buffer ); 34 T remove( Buffer(T) & mutex buffer ); // forward 38 35 39 forall( otype T ) 40 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) { 41 if ( count == BufferSize ) waitfor( remove, buffer ); 42 elements[back] = elem; 43 back = ( back + 1 ) % BufferSize; 44 count += 1; 45 } 36 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) { 37 if ( count == BufferSize ) waitfor( remove, buffer ); 38 elements[back] = elem; 39 back = ( back + 1 ) % BufferSize; 40 count += 1; 41 } // insert 46 42 47 forall( otype T ) 48 T remove( Buffer(T) & mutex buffer ) with( buffer ) { 49 if ( count == 0 ) waitfor( insert, buffer );50 T elem = elements[front];51 front = ( front + 1 ) % BufferSize;52 count -= 1;53 return elem;43 T remove( Buffer(T) & mutex buffer ) with( buffer ) { 44 if ( count == 0 ) waitfor( insert, buffer ); 45 T elem = elements[front]; 46 front = ( front + 1 ) % BufferSize; 47 count -= 1; 48 return elem; 49 } // remove 54 50 } 55 51
Note: See TracChangeset
for help on using the changeset viewer.