Changes in src/tests/datingService.c [6c7b1e7:4cedd9f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/datingService.c
r6c7b1e7 r4cedd9f 1 // -*- Mode: C -*- 2 // 1 // -*- Mode: C -*- 2 // 3 3 // The contents of this file are covered under the licence agreement in the 4 4 // file "LICENCE" distributed with Cforall. 5 // 6 // datingService.c -- 7 // 5 // 6 // datingService.c -- 7 // 8 8 // Author : Peter A. Buhr 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:11 201712 // Update Count : 1 513 // 11 // Last Modified On : Mon Oct 30 17:58:41 2017 12 // Update Count : 14 13 // 14 14 15 #include <stdlib> // rand om15 #include <stdlib> // rand48 16 16 #include <fstream> 17 17 #include <kernel> 18 18 #include <thread> 19 19 #include <unistd.h> // getpid 20 21 bool empty( condition & c ) {22 return c.blocked.head == NULL;23 }24 20 25 21 enum { NoOfPairs = 20 }; … … 31 27 32 28 unsigned int girl( DatingService & mutex ds, unsigned int PhoneNo, unsigned int ccode ) { 33 if ( empty( ds.Boys[ccode] ) ) {34 wait( &ds.Girls[ccode] );29 if ( is_empty( ds.Boys[ccode] ) ) { 30 wait( ds.Girls[ccode] ); 35 31 ds.GirlPhoneNo = PhoneNo; 36 32 } else { 37 33 ds.GirlPhoneNo = PhoneNo; 38 signal_block( &ds.Boys[ccode] );34 signal_block( ds.Boys[ccode] ); 39 35 } // if 40 36 return ds.BoyPhoneNo; … … 42 38 43 39 unsigned int boy( DatingService & mutex ds, unsigned int PhoneNo, unsigned int ccode ) { 44 if ( empty( ds.Girls[ccode] ) ) {45 wait( &ds.Boys[ccode] );40 if ( is_empty( ds.Girls[ccode] ) ) { 41 wait( ds.Boys[ccode] ); 46 42 ds.BoyPhoneNo = PhoneNo; 47 43 } else { 48 44 ds.BoyPhoneNo = PhoneNo; 49 signal_block( &ds.Girls[ccode] );45 signal_block( ds.Girls[ccode] ); 50 46 } // if 51 47 return ds.GirlPhoneNo; … … 61 57 62 58 void main( Girl & g ) { 63 yield( rand om( 100 ) ); // don't all start at the same time59 yield( rand48( 100 ) ); // don't all start at the same time 64 60 unsigned int partner = girl( g.TheExchange, g.id, g.ccode ); 65 61 //sout | "Girl:" | g.id | "is dating Boy at" | partner | "with ccode" | g.ccode | endl; … … 79 75 80 76 void main( Boy & b ) { 81 yield( rand om( 100 ) ); // don't all start at the same time77 yield( rand48( 100 ) ); // don't all start at the same time 82 78 unsigned int partner = boy( b.TheExchange, b.id, b.ccode ); 83 79 //sout | " Boy:" | b.id | "is dating Girl" | partner | "with ccode" | b.ccode | endl; … … 96 92 Boy *boys[NoOfPairs]; 97 93 98 rand om_seed( getpid() );94 rand48seed( getpid() ); 99 95 100 96 for ( unsigned int i = 0; i < NoOfPairs; i += 1 ) {
Note: See TracChangeset
for help on using the changeset viewer.