Changes in / [cd3aee2:f739788]
- Location:
- src/tests/concurrent/examples
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/boundedBuffer.c
rcd3aee2 rf739788 8 8 // Created On : Mon Oct 30 12:45:13 2017 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Thu Dec 14 21:28:52201711 // Update Count : 3210 // Last Modified On : Wed Dec 13 21:01:49 2017 11 // Update Count : 27 12 12 // 13 13 … … 18 18 #include <unistd.h> // getpid 19 19 20 forall( otype T ) 20 21 monitor Buffer { 21 22 condition full, empty; 22 23 int front, back, count; 23 intelements[20];24 T elements[20]; 24 25 }; 25 26 26 void ?{}( Buffer & buffer ) { 27 forall( otype T ) 28 void ?{}( Buffer(T) & buffer ) { 27 29 buffer.front = buffer.back = buffer.count = 0; 28 30 } 29 31 30 int query( Buffer & buffer ) { return buffer.count; } 32 forall( otype T ) 33 int query( Buffer(T) & buffer ) { return buffer.count; } 31 34 32 void insert( Buffer & mutex buffer, int elem ) with( buffer ) { 35 forall( otype T ) 36 void insert( Buffer(T) & mutex buffer, T elem ) with( buffer ) { 33 37 if ( count == 20 ) wait( empty ); 34 38 elements[back] = elem; … … 38 42 } 39 43 40 int remove( Buffer & mutex buffer ) with( buffer ) { 44 forall( otype T ) 45 T remove( Buffer(T) & mutex buffer ) with( buffer ) { 41 46 if ( count == 0 ) wait( full ); 42 intelem = elements[front];47 T elem = elements[front]; 43 48 front = ( front + 1 ) % 20; 44 49 count -= 1; … … 48 53 49 54 thread Producer { 50 Buffer & buffer;55 Buffer(int) & buffer; 51 56 unsigned int N; 52 57 }; … … 58 63 insert( prod.buffer, -1 ); 59 64 } 60 void ?{}( Producer & prod, Buffer * buffer, unsigned int N ) {65 void ?{}( Producer & prod, Buffer(int) * buffer, unsigned int N ) { 61 66 &prod.buffer = buffer; 62 67 prod.N = N; … … 64 69 65 70 thread Consumer { 66 Buffer & buffer;71 Buffer(int) & buffer; 67 72 int & sum; // summation of producer values 68 73 }; … … 76 81 } // for 77 82 } 78 void ?{}( Consumer & cons, Buffer * buffer, int * sum ) {83 void ?{}( Consumer & cons, Buffer(int) * buffer, int * sum ) { 79 84 &cons.buffer = buffer; 80 85 &cons.sum = sum; … … 82 87 83 88 int main() { 84 Buffer buffer;89 Buffer(int) buffer; 85 90 enum { Prods = 5, Cons = 5 }; 86 91 Producer * prods[Prods]; -
src/tests/concurrent/examples/quickSort.c
rcd3aee2 rf739788 9 9 // Created On : Wed Dec 6 12:15:52 2017 10 10 // Last Modified By : Peter A. Buhr 11 // Last Modified On : Thu Dec 14 11:20:40201712 // Update Count : 1 4211 // Last Modified On : Wed Dec 13 18:20:18 2017 12 // Update Count : 138 13 13 // 14 14 … … 19 19 #include <string.h> // strcmp 20 20 21 forall( otype T | { int?<?( T, T ); } )21 forall( otype T | { T ?<?( T, T ); } ) 22 22 thread Quicksort { 23 23 T * values; // communication variables … … 25 25 }; 26 26 27 forall( otype T | { int?<?( T, T ); } )27 forall( otype T | { T ?<?( T, T ); } ) 28 28 void ?{}( Quicksort(T) & qs, T values[], int size, int depth ) { 29 29 qs.values = values; qs.low = 0; qs.high = size; qs.depth = depth; 30 30 } // Quicksort 31 31 32 forall( otype T | { int?<?( T, T ); } )32 forall( otype T | { T ?<?( T, T ); } ) 33 33 void main( Quicksort(T) & qs ) { 34 34 // nested routines: information hiding … … 140 140 unsortedfile | size; // read number of elements in the list 141 141 if ( eof( unsortedfile ) ) break; 142 // ELEMTYPE * values = anew( size ); // values to be sorted, too large to put on stack 143 ELEMTYPE * values = alloc( size ); // values to be sorted, too large to put on stack 144 // ELEMTYPE * values = (ELEMTYPE *)malloc( sizeof(ELEMTYPE) * size ); 142 ELEMTYPE * values = anew( size ); // values to be sorted, too large to put on stack 145 143 for ( int counter = 0; counter < size; counter += 1 ) { // read unsorted numbers 146 144 unsortedfile | values[counter]; … … 167 165 processor processors[ (1 << depth) - 1 ] __attribute__(( unused )); // create 2^depth-1 kernel threads 168 166 169 // ELEMTYPE * values = anew( size ); // values to be sorted, too large to put on stack 170 ELEMTYPE * values = alloc( size ); // values to be sorted, too large to put on stack 167 ELEMTYPE * values = anew( size ); // values to be sorted, too large to put on stack 171 168 for ( int counter = 0; counter < size; counter += 1 ) { // generate unsorted numbers 172 169 values[counter] = size - counter; // descending values
Note: See TracChangeset
for help on using the changeset viewer.