Changeset b067d9b for tests/concurrent/examples/boundedBufferINT.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/boundedBufferINT.cfa
r7951100 rb067d9b 1 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2017 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 : Mon Oct 30 12:45:13 2017 9 11 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Thu Apr 26 23:08:17 201811 // Update Count : 8212 // Last Modified On : Fri Jun 21 08:20:46 2019 13 // Update Count : 90 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 … … 51 53 } 52 54 53 const int Sentinel = -1;55 enum { Sentinel = -1 }; 54 56 55 57 thread Producer { … … 58 60 }; 59 61 void main( Producer & prod ) with( prod ) { 60 for ( i nt i = 1; i <= N; i += 1) {62 for ( i; 1 ~= N ) { 61 63 yield( random( 5 ) ); 62 64 insert( buffer, 1 ); … … 74 76 void main( Consumer & cons ) with( cons ) { 75 77 sum = 0; 76 for ( ;;) {78 for () { 77 79 yield( random( 5 ) ); 78 80 int item = remove( buffer ); … … 98 100 srandom( 1003 ); 99 101 100 for ( i = 0; i < Cons; i += 1 ) {// create consumers102 for ( i; Cons ) { // create consumers 101 103 cons[i] = new( &buffer, sums[i] ); 102 104 } // for 103 for ( i = 0; i < Prods; i += 1 ) {// create producers105 for ( i; Prods ) { // create producers 104 106 prods[i] = new( &buffer, 100000 ); 105 107 } // for 106 108 107 for ( i = 0; i < Prods; i += 1 ) {// wait for producers to finish109 for ( i; Prods ) { // wait for producers to finish 108 110 delete( prods[i] ); 109 111 } // for 110 for ( i = 0; i < Cons; i += 1 ) {// generate sentinal values to stop consumers112 for ( i; Cons ) { // generate sentinal values to stop consumers 111 113 insert( buffer, Sentinel ); 112 114 } // for 113 115 int sum = 0; 114 for ( i = 0; i < Cons; i += 1 ) {// wait for consumers to finish116 for ( i; Cons ) { // wait for consumers to finish 115 117 delete( cons[i] ); 116 118 sum += sums[i]; 117 119 } // for 118 sout | "total:" | sum | endl;120 sout | "total:" | sum; 119 121 } 120 122 121 123 // Local Variables: // 122 124 // tab-width: 4 // 123 // compile-command: "cfa boundedBufferINT.c " //125 // compile-command: "cfa boundedBufferINT.cfa" // 124 126 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.