Changeset 5e1adb5


Ignore:
Timestamp:
Dec 7, 2017, 1:11:45 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

use "with" clause

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/concurrent/examples/datingService.c

    r09687aa r5e1adb5  
    1 //                               -*- Mode: C -*-
    21//
    32// The contents of this file are covered under the licence agreement in the
     
    98// Created On       : Mon Oct 30 12:56:20 2017
    109// Last Modified By : Peter A. Buhr
    11 // Last Modified On : Tue Dec  5 23:06:40 2017
    12 // Update Count     : 18
     10// Last Modified On : Wed Dec  6 12:19:19 2017
     11// Update Count     : 21
    1312//
    1413
     
    2726
    2827unsigned 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
    3231        } 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
    3534        } // if
    3635        return BoyPhoneNo;
     
    3837
    3938unsigned 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
    4342        } 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
    4645        } // if
    4746        return GirlPhoneNo;
     
    5655}; // Girl
    5756
    58 void main( Girl & g ) {
     57void main( Girl & g ) with( g ) {
    5958        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;
    6362} // Girl main
    6463
     
    7473}; // Boy
    7574
    76 void main( Boy & b ) {
     75void main( Boy & b ) with( b ) {
    7776        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;
    8180} // Boy main
    8281
Note: See TracChangeset for help on using the changeset viewer.