Changes in / [f739788:cd3aee2]
- Location:
- src/tests/concurrent/examples
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/boundedBuffer.c
rf739788 rcd3aee2 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]; -
src/tests/concurrent/examples/quickSort.c
rf739788 rcd3aee2 9 9 // Created On : Wed Dec 6 12:15:52 2017 10 10 // Last Modified By : Peter A. Buhr 11 // Last Modified On : Wed Dec 13 18:20:18201712 // Update Count : 1 3811 // Last Modified On : Thu Dec 14 11:20:40 2017 12 // Update Count : 142 13 13 // 14 14 … … 19 19 #include <string.h> // strcmp 20 20 21 forall( otype T | { T?<?( T, T ); } )21 forall( otype T | { int ?<?( T, T ); } ) 22 22 thread Quicksort { 23 23 T * values; // communication variables … … 25 25 }; 26 26 27 forall( otype T | { T?<?( T, T ); } )27 forall( otype T | { int ?<?( 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 | { T?<?( T, T ); } )32 forall( otype T | { int ?<?( 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 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 ); 143 145 for ( int counter = 0; counter < size; counter += 1 ) { // read unsorted numbers 144 146 unsortedfile | values[counter]; … … 165 167 processor processors[ (1 << depth) - 1 ] __attribute__(( unused )); // create 2^depth-1 kernel threads 166 168 167 ELEMTYPE * values = anew( size ); // values to be sorted, too large to put on stack 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 168 171 for ( int counter = 0; counter < size; counter += 1 ) { // generate unsorted numbers 169 172 values[counter] = size - counter; // descending values
Note: See TracChangeset
for help on using the changeset viewer.