Changeset 6fa9e71 for src/tests/datingService.c
- Timestamp:
- Nov 8, 2017, 10:58:43 AM (6 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:
- 8e0147a
- Parents:
- d06c808 (diff), b9d0fb6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/datingService.c
rd06c808 r6fa9e71 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 … … 11 11 // Last Modified On : Mon Oct 30 23:02:11 2017 12 12 // Update Count : 15 13 // 13 // 14 14 15 15 #include <stdlib> // random … … 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;
Note: See TracChangeset
for help on using the changeset viewer.