Changeset 971d9f2 for src/tests/concurrent/examples/boundedBuffer.c
- Timestamp:
- Dec 6, 2017, 8:01:23 AM (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, resolv-new, with_gc
- Children:
- 16988e8
- Parents:
- 65197c2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/boundedBuffer.c
r65197c2 r971d9f2 8 8 // Created On : Mon Oct 30 12:45:13 2017 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Mon Oct 30 23:02:46201711 // Update Count : 910 // Last Modified On : Tue Dec 5 23:01:51 2017 11 // Update Count : 10 12 12 // 13 13 … … 30 30 int query( Buffer & buffer ) { return buffer.count; } 31 31 32 void insert( Buffer & mutex buffer, int elem ) {33 if ( buffer.count == 20 ) wait( buffer.empty );34 buffer.elements[buffer.back] = elem;35 b uffer.back = ( buffer.back + 1 ) % 20;36 buffer.count += 1;37 signal( buffer.full );32 void insert( Buffer & mutex buffer, int elem ) with( buffer ) { 33 if ( count == 20 ) wait( empty ); 34 elements[back] = elem; 35 back = ( back + 1 ) % 20; 36 count += 1; 37 signal( full ); 38 38 } 39 int remove( Buffer & mutex buffer ) {40 if ( buffer.count == 0 ) wait( buffer.full );41 int elem = buffer.elements[buffer.front];42 buffer.front = ( buffer.front + 1 ) % 20;43 buffer.count -= 1;44 signal( buffer.empty );39 int remove( Buffer & mutex buffer ) with( buffer ) { 40 if ( count == 0 ) wait( full ); 41 int elem = elements[front]; 42 front = ( front + 1 ) % 20; 43 count -= 1; 44 signal( empty ); 45 45 return elem; 46 46 }
Note: See TracChangeset
for help on using the changeset viewer.