Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (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.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 moved

Legend:

Unmodified
Added
Removed
  • tests/coroutine/prodcons.c

    rf9feab8 r90152a4  
    1 // 
     1//
    22// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // prodcons.c -- 
    8 // 
     6//
     7// prodcons.c --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Mon Sep 18 12:23:39 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Oct 30 23:06:05 2017
    13 // Update Count     : 42
    14 // 
     12// Last Modified On : Sat Aug 18 12:55:10 2018
     13// Update Count     : 51
     14//
    1515
    16 #include <fstream>
    17 #include <coroutine>
    18 #include <stdlib>                                                                               // random
     16#include <fstream.hfa>
     17#include <coroutine.hfa>
     18#include <stdlib.hfa>                                                                   // random
    1919#include <unistd.h>                                                                             // getpid
    2020
     
    2424
    2525coroutine Prod {
    26         Cons *c;
     26        Cons * c;
    2727        int N, money, receipt;
    2828};
    29 void main( Prod & prod ) {                                                              // starter ::main
     29void main( Prod & prod ) with( prod ) {                                 // starter ::main
    3030        // 1st resume starts here
    31         for ( int i = 0; i < prod.N; i += 1 ) {
     31        for ( i; N ) {                                                                          // N pairs of values
    3232                int p1 = random( 100 );
    3333                int p2 = random( 100 );
    3434                sout | p1 | " " | p2 | endl;
    35                 int status = delivery( *prod.c, p1, p2 );
    36                 sout | " $" | prod.money | endl;
     35                int status = delivery( *c, p1, p2 );
     36                sout | " $" | money | endl;
    3737                sout | status | endl;
    38                 prod.receipt += 1;
     38                receipt += 1;
    3939        }
    40         stop( *prod.c );
     40        stop( *c );
    4141        sout | "prod stops" | endl;
    4242}
     
    6464}
    6565void ^?{}( Cons & cons ) {}
    66 void main( Cons & cons ) {                                                              // starter prod
     66void main( Cons & cons ) with( cons ) {                                 // starter prod
    6767        // 1st resume starts here
    6868        int money = 1, receipt;
    69         for ( ; ! cons.done; ) {
    70                 sout | cons.p1 | " " | cons.p2 | endl;
     69        for ( ; ! done; ) {
     70                sout | p1 | " " | p2 | endl;
    7171                sout | " $" | money | endl;
    72                 cons.status += 1;
    73                 receipt = payment( *cons.p, money );
     72                status += 1;
     73                receipt = payment( *p, money );
    7474                sout | " #" | receipt | endl;
    7575                money += 1;
     
    9090        Prod prod;
    9191        Cons cons = { prod };
    92         random_seed( /* getpid() */ 103 );                                      // fixed seed for testing
     92        srandom( /* getpid() */ 103 );                                          // fixed seed for testing
    9393        start( prod, 5, cons );
    9494        sout | "main stops" | endl;
Note: See TracChangeset for help on using the changeset viewer.