- Timestamp:
- May 2, 2018, 4:18:37 PM (7 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
- Location:
- src/tests/concurrent/examples
- Files:
-
- 2 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 -
src/tests/concurrent/examples/boundedBufferINT.c
r6d539f83 r623c16a 8 8 // Created On : Mon Oct 30 12:45:13 2017 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Fri Apr 20 22:18:18201811 // Update Count : 7810 // Last Modified On : Thu Apr 26 23:08:17 2018 11 // Update Count : 82 12 12 // 13 13 … … 22 22 enum { BufferSize = 50 }; 23 23 24 forall( otype T ) 25 monitor Buffer {26 condition full, empty;27 int front, back, count;28 T elements[BufferSize];29 }; 24 forall( otype T ) { 25 monitor Buffer { 26 condition full, empty; 27 int front, back, count; 28 T elements[BufferSize]; 29 }; // Buffer 30 30 31 forall( otype T ) 32 void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; } 31 void ?{}( Buffer(T) & buffer ) with( buffer ) { [front, back, count] = 0; } 33 32 34 forall( otype T ) 35 int query( Buffer(T) & buffer ) { return buffer.count; } 33 int query( Buffer(T) & buffer ) { return buffer.count; } // read-only, no mutual exclusion 36 34 37 forall( otype T ) 38 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) { 39 if ( count == BufferSize ) wait( empty ); 40 elements[back] = elem; 41 back = ( back + 1 ) % BufferSize; 42 count += 1; 43 signal( full ); 44 } 35 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) { 36 if ( count == BufferSize ) wait( empty ); 37 elements[back] = elem; 38 back = ( back + 1 ) % BufferSize; 39 count += 1; 40 signal( full ); 41 } // insert 45 42 46 forall( otype T ) 47 T remove( Buffer(T) & mutex buffer ) with( buffer ) { 48 if ( count == 0 ) wait( full );49 T elem = elements[front];50 front = ( front + 1 ) % BufferSize;51 count -= 1;52 signal( empty );53 return elem;43 T remove( Buffer(T) & mutex buffer ) with( buffer ) { 44 if ( count == 0 ) wait( full ); 45 T elem = elements[front]; 46 front = ( front + 1 ) % BufferSize; 47 count -= 1; 48 signal( empty ); 49 return elem; 50 } // remove 54 51 } 55 52
Note: See TracChangeset
for help on using the changeset viewer.