Changeset 1edf37f for src/tests/concurrent/examples
- Timestamp:
- Dec 14, 2017, 9:35:09 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, resolv-new, with_gc
- Children:
- fe4840a
- Parents:
- a1ecdd1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/boundedBuffer.c
ra1ecdd1 r1edf37f 8 8 // Created On : Mon Oct 30 12:45:13 2017 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Wed Dec 13 21:01:49201711 // Update Count : 2710 // Last Modified On : Thu Dec 14 21:28:52 2017 11 // Update Count : 32 12 12 // 13 13 … … 18 18 #include <unistd.h> // getpid 19 19 20 forall( otype T )21 20 monitor Buffer { 22 21 condition full, empty; 23 22 int front, back, count; 24 Telements[20];23 int elements[20]; 25 24 }; 26 25 27 forall( otype T ) 28 void ?{}( Buffer(T) & buffer ) { 26 void ?{}( Buffer & buffer ) { 29 27 buffer.front = buffer.back = buffer.count = 0; 30 28 } 31 29 32 forall( otype T ) 33 int query( Buffer(T) & buffer ) { return buffer.count; } 30 int query( Buffer & buffer ) { return buffer.count; } 34 31 35 forall( otype T ) 36 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) { 32 void insert( Buffer & mutex buffer, int elem ) with( buffer ) { 37 33 if ( count == 20 ) wait( empty ); 38 34 elements[back] = elem; … … 42 38 } 43 39 44 forall( otype T ) 45 T remove( Buffer(T) & mutex buffer ) with( buffer ) { 40 int remove( Buffer & mutex buffer ) with( buffer ) { 46 41 if ( count == 0 ) wait( full ); 47 Telem = elements[front];42 int elem = elements[front]; 48 43 front = ( front + 1 ) % 20; 49 44 count -= 1; … … 53 48 54 49 thread Producer { 55 Buffer (int)& buffer;50 Buffer & buffer; 56 51 unsigned int N; 57 52 }; … … 63 58 insert( prod.buffer, -1 ); 64 59 } 65 void ?{}( Producer & prod, Buffer (int)* buffer, unsigned int N ) {60 void ?{}( Producer & prod, Buffer * buffer, unsigned int N ) { 66 61 &prod.buffer = buffer; 67 62 prod.N = N; … … 69 64 70 65 thread Consumer { 71 Buffer (int)& buffer;66 Buffer & buffer; 72 67 int & sum; // summation of producer values 73 68 }; … … 81 76 } // for 82 77 } 83 void ?{}( Consumer & cons, Buffer (int)* buffer, int * sum ) {78 void ?{}( Consumer & cons, Buffer * buffer, int * sum ) { 84 79 &cons.buffer = buffer; 85 80 &cons.sum = sum; … … 87 82 88 83 int main() { 89 Buffer (int)buffer;84 Buffer buffer; 90 85 enum { Prods = 5, Cons = 5 }; 91 86 Producer * prods[Prods];
Note: See TracChangeset
for help on using the changeset viewer.