- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/datingService.c
r948887f 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 ) {
Note: See TracChangeset
for help on using the changeset viewer.