Changeset 90152a4 for tests/coroutine/prodcons.c
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 years ago)
- 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. - File:
-
- 1 moved
-
tests/coroutine/prodcons.c (moved) (moved from src/tests/coroutine/prodcons.c ) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/coroutine/prodcons.c
rf9feab8 r90152a4 1 // 1 // 2 2 // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo 3 3 // 4 4 // The contents of this file are covered under the licence agreement in the 5 5 // file "LICENCE" distributed with Cforall. 6 // 7 // prodcons.c -- 8 // 6 // 7 // prodcons.c -- 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Mon Sep 18 12:23:39 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Oct 30 23:06:05 201713 // Update Count : 4214 // 12 // Last Modified On : Sat Aug 18 12:55:10 2018 13 // Update Count : 51 14 // 15 15 16 #include <fstream >17 #include <coroutine >18 #include <stdlib >// random16 #include <fstream.hfa> 17 #include <coroutine.hfa> 18 #include <stdlib.hfa> // random 19 19 #include <unistd.h> // getpid 20 20 … … 24 24 25 25 coroutine Prod { 26 Cons * c;26 Cons * c; 27 27 int N, money, receipt; 28 28 }; 29 void main( Prod & prod ) {// starter ::main29 void main( Prod & prod ) with( prod ) { // starter ::main 30 30 // 1st resume starts here 31 for ( i nt i = 0; i < prod.N; i += 1 ) {31 for ( i; N ) { // N pairs of values 32 32 int p1 = random( 100 ); 33 33 int p2 = random( 100 ); 34 34 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; 37 37 sout | status | endl; 38 prod.receipt += 1;38 receipt += 1; 39 39 } 40 stop( * prod.c );40 stop( *c ); 41 41 sout | "prod stops" | endl; 42 42 } … … 64 64 } 65 65 void ^?{}( Cons & cons ) {} 66 void main( Cons & cons ) {// starter prod66 void main( Cons & cons ) with( cons ) { // starter prod 67 67 // 1st resume starts here 68 68 int money = 1, receipt; 69 for ( ; ! cons.done; ) {70 sout | cons.p1 | " " | cons.p2 | endl;69 for ( ; ! done; ) { 70 sout | p1 | " " | p2 | endl; 71 71 sout | " $" | money | endl; 72 cons.status += 1;73 receipt = payment( * cons.p, money );72 status += 1; 73 receipt = payment( *p, money ); 74 74 sout | " #" | receipt | endl; 75 75 money += 1; … … 90 90 Prod prod; 91 91 Cons cons = { prod }; 92 random_seed( /* getpid() */ 103 );// fixed seed for testing92 srandom( /* getpid() */ 103 ); // fixed seed for testing 93 93 start( prod, 5, cons ); 94 94 sout | "main stops" | endl;
Note:
See TracChangeset
for help on using the changeset viewer.