Ignore:
Timestamp:
Dec 6, 2017, 8:01:23 AM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, 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, resolv-new, with_gc
Children:
16988e8
Parents:
65197c2
Message:

add "with" clause to test programs

File:
1 edited

Legend:

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

    r65197c2 r971d9f2  
    99// Created On       : Mon Oct 30 12:56:20 2017
    1010// Last Modified By : Peter A. Buhr
    11 // Last Modified On : Mon Oct 30 23:02:11 2017
    12 // Update Count     : 15
     11// Last Modified On : Tue Dec  5 23:06:40 2017
     12// Update Count     : 18
    1313//
    1414
     
    2626}; // DatingService
    2727
    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;
     28unsigned 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;
    3232        } else {
    33                 ds.GirlPhoneNo = PhoneNo;
    34                 signal_block( ds.Boys[ccode] );
     33                GirlPhoneNo = PhoneNo;
     34                signal_block( Boys[ccode] );
    3535        } // if
    36         return ds.BoyPhoneNo;
     36        return BoyPhoneNo;
    3737} // DatingService girl
    3838
    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;
     39unsigned 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;
    4343        } else {
    44                 ds.BoyPhoneNo = PhoneNo;
    45                 signal_block( ds.Girls[ccode] );
     44                BoyPhoneNo = PhoneNo;
     45                signal_block( Girls[ccode] );
    4646        } // if
    47         return ds.GirlPhoneNo;
     47        return GirlPhoneNo;
    4848} // DatingService boy
    4949
     
    5959        yield( random( 100 ) );                                                         // don't all start at the same time
    6060        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;
    6262        girlck[g.id] = partner;
    6363} // Girl main
     
    7777        yield( random( 100 ) );                                                         // don't all start at the same time
    7878        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;
    8080        boyck[b.id] = partner;
    8181} // Boy main
     
    9292        Boy  *boys[NoOfPairs];
    9393
    94         random_seed( getpid() );
     94        random_seed( /*getpid()*/ 103 );
    9595
    9696        for ( unsigned int i = 0; i < NoOfPairs; i += 1 ) {
Note: See TracChangeset for help on using the changeset viewer.