Changeset 5e1adb5
- Timestamp:
- Dec 7, 2017, 1:11:45 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:
- 1485c1a, 6ba16fa, 8da74119
- Parents:
- 09687aa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/datingService.c
r09687aa r5e1adb5 1 // -*- Mode: C -*-2 1 // 3 2 // The contents of this file are covered under the licence agreement in the … … 9 8 // Created On : Mon Oct 30 12:56:20 2017 10 9 // Last Modified By : Peter A. Buhr 11 // Last Modified On : Tue Dec 5 23:06:40201712 // Update Count : 1810 // Last Modified On : Wed Dec 6 12:19:19 2017 11 // Update Count : 21 13 12 // 14 13 … … 27 26 28 27 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; 28 if ( is_empty( Boys[ccode] ) ) { // no compatible boy ? 29 wait( Girls[ccode] ); // wait for boy 30 GirlPhoneNo = PhoneNo; // make phone number available 32 31 } else { 33 GirlPhoneNo = PhoneNo; 34 signal_block( Boys[ccode] ); 32 GirlPhoneNo = PhoneNo; // make phone number available 33 signal_block( Boys[ccode] ); // restart boy to set phone number 35 34 } // if 36 35 return BoyPhoneNo; … … 38 37 39 38 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; 39 if ( is_empty( Girls[ccode] ) ) { // no compatible girl ? 40 wait( Boys[ccode] ); // wait for girl 41 BoyPhoneNo = PhoneNo; // make phone number available 43 42 } else { 44 BoyPhoneNo = PhoneNo; 45 signal_block( Girls[ccode] ); 43 BoyPhoneNo = PhoneNo; // make phone number available 44 signal_block( Girls[ccode] ); // restart girl to set phone number 46 45 } // if 47 46 return GirlPhoneNo; … … 56 55 }; // Girl 57 56 58 void main( Girl & g ) {57 void main( Girl & g ) with( g ) { 59 58 yield( random( 100 ) ); // don't all start at the same time 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;62 girlck[ g.id] = partner;59 unsigned int partner = girl( TheExchange, id, ccode ); 60 sout | "Girl:" | id | "is dating Boy at" | partner | "with ccode" | ccode | endl; 61 girlck[id] = partner; 63 62 } // Girl main 64 63 … … 74 73 }; // Boy 75 74 76 void main( Boy & b ) {75 void main( Boy & b ) with( b ) { 77 76 yield( random( 100 ) ); // don't all start at the same time 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;80 boyck[ b.id] = partner;77 unsigned int partner = boy( TheExchange, id, ccode ); 78 sout | " Boy:" | id | "is dating Girl" | partner | "with ccode" | ccode | endl; 79 boyck[id] = partner; 81 80 } // Boy main 82 81
Note: See TracChangeset
for help on using the changeset viewer.