Changeset 971d9f2 for src/tests/concurrent/examples
- Timestamp:
- Dec 6, 2017, 8:01:23 AM (8 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
- Location:
- src/tests/concurrent/examples
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/.expect/datingService.txt
r65197c2 r971d9f2 1 Girl:17 is dating Boy at 2 with ccode 17 2 Boy:2 is dating Girl 17 with ccode 17 3 Boy:14 is dating Girl 5 with ccode 5 4 Girl:5 is dating Boy at 14 with ccode 5 5 Boy:9 is dating Girl 10 with ccode 10 6 Girl:10 is dating Boy at 9 with ccode 10 7 Boy:1 is dating Girl 18 with ccode 18 8 Girl:18 is dating Boy at 1 with ccode 18 9 Boy:16 is dating Girl 3 with ccode 3 10 Girl:3 is dating Boy at 16 with ccode 3 11 Boy:5 is dating Girl 14 with ccode 14 12 Girl:14 is dating Boy at 5 with ccode 14 13 Boy:15 is dating Girl 4 with ccode 4 14 Girl:4 is dating Boy at 15 with ccode 4 15 Girl:0 is dating Boy at 19 with ccode 0 16 Boy:19 is dating Girl 0 with ccode 0 17 Girl:9 is dating Boy at 10 with ccode 9 18 Boy:10 is dating Girl 9 with ccode 9 19 Girl:11 is dating Boy at 8 with ccode 11 20 Boy:8 is dating Girl 11 with ccode 11 21 Boy:12 is dating Girl 7 with ccode 7 22 Girl:7 is dating Boy at 12 with ccode 7 23 Boy:11 is dating Girl 8 with ccode 8 24 Girl:8 is dating Boy at 11 with ccode 8 25 Girl:16 is dating Boy at 3 with ccode 16 26 Boy:3 is dating Girl 16 with ccode 16 27 Girl:15 is dating Boy at 4 with ccode 15 28 Boy:4 is dating Girl 15 with ccode 15 29 Girl:19 is dating Boy at 0 with ccode 19 30 Boy:0 is dating Girl 19 with ccode 19 31 Girl:2 is dating Boy at 17 with ccode 2 32 Boy:17 is dating Girl 2 with ccode 2 33 Boy:13 is dating Girl 6 with ccode 6 34 Girl:6 is dating Boy at 13 with ccode 6 35 Boy:7 is dating Girl 12 with ccode 12 36 Girl:12 is dating Boy at 7 with ccode 12 37 Girl:13 is dating Boy at 6 with ccode 13 38 Boy:6 is dating Girl 13 with ccode 13 39 Girl:1 is dating Boy at 18 with ccode 1 40 Boy:18 is dating Girl 1 with ccode 1 -
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 } -
src/tests/concurrent/examples/datingService.c
r65197c2 r971d9f2 9 9 // Created On : Mon Oct 30 12:56:20 2017 10 10 // Last Modified By : Peter A. Buhr 11 // Last Modified On : Mon Oct 30 23:02:11201712 // Update Count : 1 511 // Last Modified On : Tue Dec 5 23:06:40 2017 12 // Update Count : 18 13 13 // 14 14 … … 26 26 }; // DatingService 27 27 28 unsigned int girl( DatingService & mutex ds, unsigned int PhoneNo, unsigned int ccode ) {29 if ( is_empty( ds.Boys[ccode] ) ) {30 wait( ds.Girls[ccode] );31 ds.GirlPhoneNo = PhoneNo;28 unsigned int girl( DatingService & mutex ds, unsigned int PhoneNo, unsigned int ccode ) with( ds ) { 29 if ( is_empty( Boys[ccode] ) ) { 30 wait( Girls[ccode] ); 31 GirlPhoneNo = PhoneNo; 32 32 } else { 33 ds.GirlPhoneNo = PhoneNo;34 signal_block( ds.Boys[ccode] );33 GirlPhoneNo = PhoneNo; 34 signal_block( Boys[ccode] ); 35 35 } // if 36 return ds.BoyPhoneNo;36 return BoyPhoneNo; 37 37 } // DatingService girl 38 38 39 unsigned int boy( DatingService & mutex ds, unsigned int PhoneNo, unsigned int ccode ) {40 if ( is_empty( ds.Girls[ccode] ) ) {41 wait( ds.Boys[ccode] );42 ds.BoyPhoneNo = PhoneNo;39 unsigned int boy( DatingService & mutex ds, unsigned int PhoneNo, unsigned int ccode ) with( ds ) { 40 if ( is_empty( Girls[ccode] ) ) { 41 wait( Boys[ccode] ); 42 BoyPhoneNo = PhoneNo; 43 43 } else { 44 ds.BoyPhoneNo = PhoneNo;45 signal_block( ds.Girls[ccode] );44 BoyPhoneNo = PhoneNo; 45 signal_block( Girls[ccode] ); 46 46 } // if 47 return ds.GirlPhoneNo;47 return GirlPhoneNo; 48 48 } // DatingService boy 49 49 … … 59 59 yield( random( 100 ) ); // don't all start at the same time 60 60 unsigned int partner = girl( g.TheExchange, g.id, g.ccode ); 61 //sout | "Girl:" | g.id | "is dating Boy at" | partner | "with ccode" | g.ccode | endl;61 sout | "Girl:" | g.id | "is dating Boy at" | partner | "with ccode" | g.ccode | endl; 62 62 girlck[g.id] = partner; 63 63 } // Girl main … … 77 77 yield( random( 100 ) ); // don't all start at the same time 78 78 unsigned int partner = boy( b.TheExchange, b.id, b.ccode ); 79 //sout | " Boy:" | b.id | "is dating Girl" | partner | "with ccode" | b.ccode | endl;79 sout | " Boy:" | b.id | "is dating Girl" | partner | "with ccode" | b.ccode | endl; 80 80 boyck[b.id] = partner; 81 81 } // Boy main … … 92 92 Boy *boys[NoOfPairs]; 93 93 94 random_seed( getpid());94 random_seed( /*getpid()*/ 103 ); 95 95 96 96 for ( unsigned int i = 0; i < NoOfPairs; i += 1 ) { -
src/tests/concurrent/examples/matrixSum.c
r65197c2 r971d9f2 11 11 // Created On : Mon Oct 9 08:29:28 2017 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Sun Oct 29 21:08:48201714 // Update Count : 213 // Last Modified On : Tue Dec 5 22:56:46 2017 14 // Update Count : 4 15 15 // 16 16 … … 29 29 } 30 30 31 void main( Adder & adder ) {32 * adder.subtotal = 0;33 for ( int c = 0; c < adder.cols; c += 1 ) {34 * adder.subtotal += adder.row[c];31 void main( Adder & adder ) with( adder ) { 32 *subtotal = 0; 33 for ( int c = 0; c < cols; c += 1 ) { 34 *subtotal += row[c]; 35 35 } // for 36 36 }
Note:
See TracChangeset
for help on using the changeset viewer.