Changeset e99e43f for tests/coroutine/prodcons.cfa
- Timestamp:
- Jan 10, 2019, 3:50:34 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- d97c3a4
- Parents:
- aeb8f70 (diff), 08222c7 (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. - git-author:
- Aaron Moss <a3moss@…> (01/10/19 14:46:09)
- git-committer:
- Aaron Moss <a3moss@…> (01/10/19 15:50:34)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
tests/coroutine/prodcons.cfa
raeb8f70 re99e43f 10 10 // Created On : Mon Sep 18 12:23:39 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Aug 18 12:55:10201813 // Update Count : 5 112 // Last Modified On : Wed Dec 12 23:04:49 2018 13 // Update Count : 53 14 14 // 15 15 … … 24 24 25 25 coroutine Prod { 26 Cons *c;26 Cons & c; 27 27 int N, money, receipt; 28 28 }; … … 30 30 // 1st resume starts here 31 31 for ( i; N ) { // N pairs of values 32 int p1 = random( 100 ); 33 int p2 = random( 100 ); 34 sout | p1 | " " | p2 | endl; 35 int status = delivery( *c, p1, p2 ); 36 sout | " $" | money | endl; 37 sout | status | endl; 32 int p1 = random( 100 ), p2 = random( 100 ); 33 sout | p1 | " " | p2; 34 int status = delivery( c, p1, p2 ); 35 sout | " $" | money | nl | status; 38 36 receipt += 1; 39 37 } 40 stop( *c );41 sout | "prod stops" | endl;38 stop( c ); 39 sout | "prod stops"; 42 40 } 43 41 int payment( Prod & prod, int money ) { … … 47 45 } 48 46 void start( Prod & prod, int N, Cons &c ) { 49 prod.N = N; 50 prod.c = &c; 51 prod.receipt = 0; 47 &prod.c = &c; 48 prod.[N, receipt] = [N, 0]; 52 49 resume( prod ); // activate main 53 50 } 54 51 55 52 coroutine Cons { 56 Prod *p;53 Prod & p; 57 54 int p1, p2, status; 58 55 bool done; 59 56 }; 60 57 void ?{}( Cons & cons, Prod & p ) { 61 cons.p = &p; 62 cons.status = 0; 63 cons.done = false; 58 &cons.p = &p; 59 cons.[status, done ] = [0, false]; 64 60 } 65 61 void ^?{}( Cons & cons ) {} … … 68 64 int money = 1, receipt; 69 65 for ( ; ! done; ) { 70 sout | p1 | " " | p2 | endl; 71 sout | " $" | money | endl; 66 sout | p1 | " " | p2 | nl | " $" | money; 72 67 status += 1; 73 receipt = payment( *p, money );74 sout | " #" | receipt | endl;68 receipt = payment( p, money ); 69 sout | " #" | receipt; 75 70 money += 1; 76 71 } 77 sout | "cons stops" | endl;72 sout | "cons stops"; 78 73 } 79 74 int delivery( Cons & cons, int p1, int p2 ) { 80 cons.p1 = p1; 81 cons.p2 = p2; 75 cons.[p1, p2] = [p1, p2]; 82 76 resume( cons ); // main 1st time, then 83 77 return cons.status; // cons in payment … … 92 86 srandom( /* getpid() */ 103 ); // fixed seed for testing 93 87 start( prod, 5, cons ); 94 sout | "main stops" | endl;88 sout | "main stops"; 95 89 } 96 90
Note:
See TracChangeset
for help on using the changeset viewer.