Changeset b067d9b for tests/concurrent/examples/boundedBufferEXT.cfa
- Timestamp:
- Oct 29, 2019, 4:01:24 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 773db65, 9421f3d8
- Parents:
- 7951100 (diff), 8364209 (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
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/examples/boundedBufferEXT.cfa
r7951100 rb067d9b 1 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo 3 // 2 4 // The contents of this file are covered under the licence agreement in the 3 5 // file "LICENCE" distributed with Cforall. … … 8 10 // Created On : Wed Apr 18 22:52:12 2018 9 11 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Wed May 2 16:12:58 201811 // Update Count : 712 // Last Modified On : Fri Jun 21 08:19:20 2019 13 // Update Count : 14 12 14 // 13 15 14 #include <stdlib >// random15 #include <fstream >16 #include <kernel >17 #include <thread >16 #include <stdlib.hfa> // random 17 #include <fstream.hfa> 18 #include <kernel.hfa> 19 #include <thread.hfa> 18 20 #include <unistd.h> // getpid 19 21 … … 50 52 } 51 53 52 const int Sentinel = -1;54 enum { Sentinel = -1 }; 53 55 54 56 thread Producer { … … 57 59 }; 58 60 void main( Producer & prod ) with( prod ) { 59 for ( i nt i = 1; i <= N; i += 1) {61 for ( i; 1 ~= N ) { 60 62 yield( random( 5 ) ); 61 63 insert( buffer, 1 ); … … 73 75 void main( Consumer & cons ) with( cons ) { 74 76 sum = 0; 75 for ( ;;) {77 for () { 76 78 yield( random( 5 ) ); 77 79 int item = remove( buffer ); … … 97 99 srandom( 1003 ); 98 100 99 for ( i = 0; i < Cons; i += 1 ) {// create consumers101 for ( i; Cons ) { // create consumers 100 102 cons[i] = new( &buffer, sums[i] ); 101 103 } // for 102 for ( i = 0; i < Prods; i += 1 ) {// create producers104 for ( i; Prods ) { // create producers 103 105 prods[i] = new( &buffer, 100000 ); 104 106 } // for 105 107 106 for ( i = 0; i < Prods; i += 1 ) {// wait for producers to finish108 for ( i; Prods ) { // wait for producers to finish 107 109 delete( prods[i] ); 108 110 } // for 109 for ( i = 0; i < Cons; i += 1 ) {// generate sentinal values to stop consumers111 for ( i; Cons ) { // generate sentinal values to stop consumers 110 112 insert( buffer, Sentinel ); 111 113 } // for 112 114 int sum = 0; 113 for ( i = 0; i < Cons; i += 1 ) {// wait for consumers to finish115 for ( i; Cons ) { // wait for consumers to finish 114 116 delete( cons[i] ); 115 117 sum += sums[i]; 116 118 } // for 117 sout | "total:" | sum | endl;119 sout | "total:" | sum; 118 120 } 119 121 120 122 // Local Variables: // 121 123 // tab-width: 4 // 122 // compile-command: "cfa boundedBufferEXT.c " //124 // compile-command: "cfa boundedBufferEXT.cfa" // 123 125 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.