Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/datingService.c

    r6c7b1e7 r4cedd9f  
    1 //                               -*- Mode: C -*- 
    2 // 
     1//                               -*- Mode: C -*-
     2//
    33// The contents of this file are covered under the licence agreement in the
    44// file "LICENCE" distributed with Cforall.
    5 // 
    6 // datingService.c -- 
    7 // 
     5//
     6// datingService.c --
     7//
    88// Author           : Peter A. Buhr
    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
    13 // 
     11// Last Modified On : Mon Oct 30 17:58:41 2017
     12// Update Count     : 14
     13//
    1414
    15 #include <stdlib>                                                                               // random
     15#include <stdlib>                                                                               // rand48
    1616#include <fstream>
    1717#include <kernel>
    1818#include <thread>
    1919#include <unistd.h>                                                                             // getpid
    20 
    21 bool empty( condition & c ) {
    22         return c.blocked.head == NULL;
    23 }
    2420
    2521enum { NoOfPairs = 20 };
     
    3127
    3228unsigned 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] );
    3531                ds.GirlPhoneNo = PhoneNo;
    3632        } else {
    3733                ds.GirlPhoneNo = PhoneNo;
    38                 signal_block( &ds.Boys[ccode] );
     34                signal_block( ds.Boys[ccode] );
    3935        } // if
    4036        return ds.BoyPhoneNo;
     
    4238
    4339unsigned 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] );
    4642                ds.BoyPhoneNo = PhoneNo;
    4743        } else {
    4844                ds.BoyPhoneNo = PhoneNo;
    49                 signal_block( &ds.Girls[ccode] );
     45                signal_block( ds.Girls[ccode] );
    5046        } // if
    5147        return ds.GirlPhoneNo;
     
    6157
    6258void main( Girl & g ) {
    63         yield( random( 100 ) );                                                         // don't all start at the same time
     59        yield( rand48( 100 ) );                                                         // don't all start at the same time
    6460        unsigned int partner = girl( g.TheExchange, g.id, g.ccode );
    6561        //sout | "Girl:" | g.id | "is dating Boy at" | partner | "with ccode" | g.ccode | endl;
     
    7975
    8076void main( Boy & b ) {
    81         yield( random( 100 ) );                                                         // don't all start at the same time
     77        yield( rand48( 100 ) );                                                         // don't all start at the same time
    8278        unsigned int partner = boy( b.TheExchange, b.id, b.ccode );
    8379        //sout | " Boy:" | b.id | "is dating Girl" | partner | "with ccode" | b.ccode | endl;
     
    9692        Boy  *boys[NoOfPairs];
    9793
    98         random_seed( getpid() );
     94        rand48seed( getpid() );
    9995
    10096        for ( unsigned int i = 0; i < NoOfPairs; i += 1 ) {
Note: See TracChangeset for help on using the changeset viewer.