Changeset b067d9b for tests/concurrent
- 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. - Location:
- tests/concurrent
- Files:
-
- 6 added
- 41 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: // -
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: // -
tests/concurrent/examples/datingService.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:56:20 2017 9 11 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Sun May 27 09:05:18 201811 // Update Count : 2612 // Last Modified On : Fri Jun 21 11:32:34 2019 13 // Update Count : 38 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 … … 33 35 signal_block( Boys[ccode] ); // restart boy to set phone number 34 36 } // if 37 sout | "Girl:" | PhoneNo | "is dating Boy at" | BoyPhoneNo | "with ccode" | ccode; 35 38 return BoyPhoneNo; 36 39 } // DatingService girl … … 44 47 signal_block( Girls[ccode] ); // restart girl to set phone number 45 48 } // if 49 sout | " Boy:" | PhoneNo | "is dating Girl" | GirlPhoneNo | "with ccode" | ccode; 46 50 return GirlPhoneNo; 47 51 } // DatingService boy … … 58 62 yield( random( 100 ) ); // don't all start at the same time 59 63 unsigned int partner = girl( TheExchange, id, ccode ); 60 sout | "Girl:" | id | "is dating Boy at" | partner | "with ccode" | ccode | endl;61 64 girlck[id] = partner; 62 65 } // Girl main … … 69 72 70 73 thread Boy { 71 DatingService & TheExchange;74 DatingService & TheExchange; 72 75 unsigned int id, ccode; 73 76 }; // Boy … … 76 79 yield( random( 100 ) ); // don't all start at the same time 77 80 unsigned int partner = boy( TheExchange, id, ccode ); 78 sout | " Boy:" | id | "is dating Girl" | partner | "with ccode" | ccode | endl;79 81 boyck[id] = partner; 80 82 } // Boy main … … 93 95 srandom( /*getpid()*/ 103 ); 94 96 95 for ( unsigned int i = 0; i < CompCodes; i += 1) {96 girls[i] = new( &TheExchange, i, i ); 97 for ( i; (unsigned int)CompCodes ) { 98 girls[i] = new( &TheExchange, i, i ); // TheExchange constructor needs unsigned int 97 99 boys[i] = new( &TheExchange, i, CompCodes - ( i + 1 ) ); 98 100 } // for 99 101 100 for ( unsigned int i = 0; i < CompCodes; i += 1) {102 for ( i; CompCodes ) { 101 103 delete( boys[i] ); 102 104 delete( girls[i] ); 103 105 } // for 104 106 105 for ( unsigned int i = 0; i < CompCodes; i += 1) {107 for ( i; CompCodes ) { 106 108 if ( girlck[ boyck[i] ] != boyck[ girlck[i] ] ) abort(); 107 109 } // for … … 110 112 // Local Variables: // 111 113 // tab-width: 4 // 112 // compile-command: "cfa datingService.c " //114 // compile-command: "cfa datingService.cfa" // 113 115 // End: // -
tests/concurrent/examples/matrixSum.cfa
r7951100 rb067d9b 1 // -*- Mode: C -*- 2 // 1 // 3 2 // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo 4 3 // 5 4 // The contents of this file are covered under the licence agreement in the 6 5 // file "LICENCE" distributed with Cforall. 7 // 8 // matrixSum.c --9 // 6 // 7 // matrixSum.cfa -- 8 // 10 9 // Author : Peter A. Buhr 11 10 // Created On : Mon Oct 9 08:29:28 2017 12 11 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Fri May 25 09:34:27 201814 // Update Count : 1 015 // 12 // Last Modified On : Wed Feb 20 08:37:53 2019 13 // Update Count : 16 14 // 16 15 17 #include <fstream >18 #include <kernel >19 #include <thread >16 #include <fstream.hfa> 17 #include <kernel.hfa> 18 #include <thread.hfa> 20 19 21 20 thread Adder { … … 30 29 void main( Adder & adder ) with( adder ) { // thread starts here 31 30 subtotal = 0; 32 for ( int c = 0; c < cols; c += 1) {31 for ( c; cols ) { 33 32 subtotal += row[c]; 34 33 } // for … … 36 35 37 36 int main() { 38 constint rows = 10, cols = 1000;37 /* const */ int rows = 10, cols = 1000; 39 38 int matrix[rows][cols], subtotals[rows], total = 0; 40 39 processor p; // add kernel thread 41 40 42 for ( int r = 0; r < rows; r += 1) {43 for ( int c = 0; c < cols; c += 1) {41 for ( r; rows ) { 42 for ( c; cols ) { 44 43 matrix[r][c] = 1; 45 44 } // for 46 45 } // for 47 46 Adder * adders[rows]; 48 for ( int r = 0; r < rows; r += 1 ) {// start threads to sum rows47 for ( r; rows ) { // start threads to sum rows 49 48 adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] }; 50 49 // adders[r] = new( matrix[r], cols, &subtotals[r] ); 51 50 } // for 52 for ( int r = 0; r < rows; r += 1 ) {// wait for threads to finish51 for ( r; rows ) { // wait for threads to finish 53 52 delete( adders[r] ); 54 53 total += subtotals[r]; // total subtotals 55 54 } // for 56 sout | total | endl;55 sout | total; 57 56 } 58 57 59 58 // Local Variables: // 60 59 // tab-width: 4 // 61 // compile-command: "cfa matrixSum.c " //60 // compile-command: "cfa matrixSum.cfa" // 62 61 // End: // -
tests/concurrent/examples/quickSort.cfa
r7951100 rb067d9b 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo 1 3 // 2 4 // The contents of this file are covered under the licence agreement in the … … 9 11 // Created On : Wed Dec 6 12:15:52 2017 10 12 // Last Modified By : Peter A. Buhr 11 // Last Modified On : T ue Jan 30 15:58:58 201812 // Update Count : 1 6213 // Last Modified On : Thu Oct 10 13:58:18 2019 14 // Update Count : 176 13 15 // 14 16 15 #include <fstream >16 #include <stdlib >17 #include <kernel >18 #include <thread >17 #include <fstream.hfa> 18 #include <stdlib.hfa> 19 #include <kernel.hfa> 20 #include <thread.hfa> 19 21 #include <string.h> // strcmp 20 22 … … 64 66 if ( depth > 0 ) { 65 67 depth -= 1; 66 Quicksort rqs = { values, low, right, depth }; // concurrently sort upper half 67 //Quicksort lqs( values, left, high, depth ); // concurrently sort lower half 68 sort( values, left, high, depth ); // concurrently sort lower half 68 Quicksort lqs = { values, low, right, depth }; // concurrently sort lower half 69 Quicksort rqs = { values, left, high, depth }; // concurrently sort upper half 70 // Quicksort lqs = { values, low, right, depth }; // concurrently sort lower half 71 // sort( values, left, high, depth ); // concurrently sort upper half 69 72 } else { 70 73 sort( values, low, right, 0 ); // sequentially sort lower half … … 88 91 89 92 void usage( char * argv[] ) { 90 sout | "Usage:" | argv[0] | "( -s unsorted-file [ sorted-file ] | -t size (>= 0) [ depth (>= 0) ] )" | endl;93 sout | "Usage:" | argv[0] | "( -s unsorted-file [ sorted-file ] | -t size (>= 0) [ depth (>= 0) ] )"; 91 94 exit( EXIT_FAILURE ); // TERMINATE! 92 95 } // usage … … 114 117 &sortedfile = new( (const char *)argv[2] ); // open the output file 115 118 if ( fail( sortedfile ) ) { 116 serr | "Error! Could not open sorted output file \"" | argv[2] | "\"" | endl;119 serr | "Error! Could not open sorted output file \"" | argv[2] | "\""; 117 120 usage( argv ); 118 121 } // if … … 121 124 &unsortedfile = new( (const char *)argv[1] ); // open the input file 122 125 if ( fail( unsortedfile ) ) { 123 serr | "Error! Could not open unsorted input file \"" | argv[1] | "\"" | endl;126 serr | "Error! Could not open unsorted input file \"" | argv[1] | "\""; 124 127 usage( argv ); 125 128 } // if … … 127 130 } // if 128 131 } // if 132 sortedfile | nlOff; // turn off auto newline 129 133 130 134 enum { ValuesPerLine = 22 }; // number of values printed per line 131 135 132 136 if ( &unsortedfile ) { // generate output ? 133 for ( ;;) {137 for () { 134 138 unsortedfile | size; // read number of elements in the list 135 139 if ( eof( unsortedfile ) ) break; 136 140 int * values = alloc( size ); // values to be sorted, too large to put on stack 137 for ( int counter = 0; counter < size; counter += 1 ) {// read unsorted numbers141 for ( counter; size ) { // read unsorted numbers 138 142 unsortedfile | values[counter]; 139 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | endl | " ";143 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 140 144 sortedfile | values[counter]; 141 145 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 142 146 } // for 143 sortedfile | endl;147 sortedfile | nl; 144 148 if ( size > 0 ) { // values to sort ? 145 149 Quicksort QS = { values, size - 1, 0 }; // sort values 146 150 } // wait until sort tasks terminate 147 for ( int counter = 0; counter < size; counter += 1 ) {// print sorted list148 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | endl | " ";151 for ( counter; size ) { // print sorted list 152 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 149 153 sortedfile | values[counter]; 150 154 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 151 155 } // for 152 sortedfile | endl | endl;156 sortedfile | nl | nl; 153 157 154 158 delete( values ); … … 159 163 processor processors[ (1 << depth) - 1 ] __attribute__(( unused )); // create 2^depth-1 kernel threads 160 164 161 int * values = alloc( size ); // values to be sorted, too large to put on stack162 for ( int counter = 0; counter < size; counter += 1 ) {// generate unsorted numbers165 int * values = alloc( size ); // values to be sorted, too large to put on stack 166 for ( counter; size ) { // generate unsorted numbers 163 167 values[counter] = size - counter; // descending values 168 } // for 169 for ( int i = 0; i < 200; i +=1 ) { // random shuffle a few values 170 swap( values[rand() % size], values[rand() % size] ); 164 171 } // for 165 172 { … … 167 174 } // wait until sort tasks terminate 168 175 169 // for ( int counter = 0; counter < size - 1; counter += 1 ) {// check sorting176 // for ( counter; size - 1 ) { // check sorting 170 177 // if ( values[counter] > values[counter + 1] ) abort(); 171 178 // } // for … … 175 182 } // main 176 183 184 // for depth in 0 1 2 3 4 5 ; do echo "sort 500000000 values with ${depth} depth" ; time -f "%Uu %Ss %E %Mkb" a.out -t 500000000 ${depth} ; done 185 177 186 // Local Variables: // 178 187 // tab-width: 4 // 179 // compile-command: "cfa quickSort.c " //188 // compile-command: "cfa quickSort.cfa" // 180 189 // End: // -
tests/concurrent/monitor.cfa
r7951100 rb067d9b 1 #include <fstream >2 #include <kernel >3 #include <monitor >4 #include <thread >1 #include <fstream.hfa> 2 #include <kernel.hfa> 3 #include <monitor.hfa> 4 #include <thread.hfa> 5 5 6 6 monitor global_t { … … 40 40 MyThread f[4]; 41 41 } 42 sout | global.value | endl;42 sout | global.value; 43 43 } -
tests/concurrent/multi-monitor.cfa
r7951100 rb067d9b 1 #include <fstream >2 #include <kernel >3 #include <monitor >4 #include <thread >1 #include <fstream.hfa> 2 #include <kernel.hfa> 3 #include <monitor.hfa> 4 #include <thread.hfa> 5 5 6 6 static int global12, global23, global13; … … 52 52 } 53 53 } 54 sout | global12 | global23 | global13 | endl;54 sout | global12 | global23 | global13; 55 55 } -
tests/concurrent/preempt.cfa
r7951100 rb067d9b 1 #include <kernel> 2 #include <thread> 3 #include <time> 1 #include <kernel.hfa> 2 #include <thread.hfa> 3 #include <time.hfa> 4 5 #include "long_tests.hfa" 4 6 5 7 #ifndef PREEMPTION_RATE … … 11 13 } 12 14 13 #ifdef LONG_TEST15 #ifdef TEST_LONG 14 16 static const unsigned long N = 30_000ul; 15 17 #else … … 30 32 31 33 void main(worker_t & this) { 32 while( counter < N) {34 while(TEST(counter < N)) { 33 35 __cfaabi_check_preemption(); 34 36 if( (counter % 7) == this.value ) { … … 40 42 } 41 43 __cfaabi_check_preemption(); 44 KICK_WATCHDOG; 42 45 } 43 46 } -
tests/concurrent/signal/block.cfa
r7951100 rb067d9b 7 7 8 8 9 #include <fstream> 10 #include <kernel> 11 #include <monitor> 12 #include <stdlib> 13 #include <thread> 14 #include <time> 9 #include <fstream.hfa> 10 #include <kernel.hfa> 11 #include <monitor.hfa> 12 #include <stdlib.hfa> 13 #include <thread.hfa> 14 #include <time.hfa> 15 16 #include "long_tests.hfa" 15 17 16 18 #ifndef PREEMPTION_RATE … … 22 24 } 23 25 24 #ifdef LONG_TEST26 #ifdef TEST_LONG 25 27 static const unsigned long N = 150_000ul; 26 28 #else … … 55 57 56 58 if(a.last_thread != a.last_signaller || b.last_thread != b.last_signaller ) { 57 sout | "ERROR Barging detected, expected" | a.last_signaller | b.last_signaller | "got" | a.last_thread | b.last_thread | endl;59 sout | "ERROR Barging detected, expected" | a.last_signaller | b.last_signaller | "got" | a.last_thread | b.last_thread; 58 60 abort(); 59 61 } … … 66 68 thread Waiter {}; 67 69 void main( Waiter & this ) { 68 for( int i = 0; i < N; i++ ) {70 for( int i = 0; TEST(i < N); i++ ) { 69 71 wait_op( globalA, globalB, i ); 72 KICK_WATCHDOG; 70 73 } 71 74 } … … 82 85 83 86 if( ! signal_block( cond ) ) { 84 sout | "ERROR expected to be able to signal" | endl;87 sout | "ERROR expected to be able to signal"; 85 88 abort(); 86 89 } … … 89 92 90 93 if(a.last_thread != next || b.last_thread != next) { 91 sout | "ERROR Barging detected, expected" | next | "got" | a.last_thread | b.last_thread | endl;94 sout | "ERROR Barging detected, expected" | next | "got" | a.last_thread | b.last_thread; 92 95 abort(); 93 96 } … … 127 130 Signaller s[4]; 128 131 Barger b[13]; 129 sout | "Starting waiters" | endl;132 sout | "Starting waiters"; 130 133 { 131 134 Waiter w[3]; 132 135 } 133 sout | "Waiters done" | endl;136 sout | "Waiters done"; 134 137 done = true; 135 138 } -
tests/concurrent/signal/disjoint.cfa
r7951100 rb067d9b 1 #include <fstream> 2 #include <kernel> 3 #include <monitor> 4 #include <thread> 5 #include <time> 1 #include <fstream.hfa> 2 #include <kernel.hfa> 3 #include <monitor.hfa> 4 #include <thread.hfa> 5 #include <time.hfa> 6 7 #include "long_tests.hfa" 6 8 7 9 #ifndef PREEMPTION_RATE … … 13 15 } 14 16 15 #ifdef LONG_TEST17 #ifdef TEST_LONG 16 18 static const unsigned long N = 300_000ul; 17 19 #else … … 64 66 wait( cond ); 65 67 if( d.state != SIGNAL ) { 66 sout | "ERROR barging!" | endl;68 sout | "ERROR barging!"; 67 69 } 68 70 69 d.counter++; 71 #if !defined(TEST_FOREVER) 72 d.counter++; 73 if( (d.counter % 1000) == 0 ) sout | d.counter; 74 #endif 70 75 71 if( (d.counter % 1000) == 0 ) sout | d.counter | endl; 72 73 return d.counter < N; 76 return TEST(d.counter < N); 74 77 } 75 78 … … 77 80 78 81 void main( Waiter & this ) { 79 while( wait( mut, data ) ) { yield(); }82 while( wait( mut, data ) ) { KICK_WATCHDOG; yield(); } 80 83 } 81 84 … … 94 97 95 98 //This is technically a mutual exclusion violation but the mutex monitor protects us 96 bool running = data.counter < N&& data.counter > 0;99 bool running = TEST(data.counter < N) && data.counter > 0; 97 100 if( data.state != SIGNAL && running ) { 98 sout | "ERROR Eager signal" | data.state | endl;101 sout | "ERROR Eager signal" | data.state; 99 102 } 100 103 } … … 121 124 Waiter w[4]; 122 125 } 123 sout | "All waiter done" | endl;126 sout | "All waiter done"; 124 127 all_done = true; 125 128 } -
tests/concurrent/signal/wait.cfa
r7951100 rb067d9b 5 5 6 6 7 #include <fstream> 8 #include <kernel> 9 #include <monitor> 10 #include <stdlib> 11 #include <thread> 12 #include <time> 7 #include <fstream.hfa> 8 #include <kernel.hfa> 9 #include <monitor.hfa> 10 #include <stdlib.hfa> 11 #include <thread.hfa> 12 #include <time.hfa> 13 14 #define __kick_rate 12000ul 15 #include "long_tests.hfa" 13 16 14 17 #ifndef PREEMPTION_RATE … … 20 23 } 21 24 22 #ifdef LONG_TEST25 #ifdef TEST_LONG 23 26 static const unsigned long N = 375_000ul; 24 27 #else … … 80 83 break; 81 84 default: 82 sout | "Something went wrong" | endl;85 sout | "Something went wrong"; 83 86 abort(); 84 87 } … … 90 93 // Waiter ABC 91 94 void main( WaiterABC & this ) { 92 for( int i = 0; i < N; i++ ) {95 for( int i = 0; TEST(i < N); i++ ) { 93 96 wait( condABC, globalA, globalB, globalC ); 97 KICK_WATCHDOG; 94 98 } 95 99 … … 100 104 // Waiter AB 101 105 void main( WaiterAB & this ) { 102 for( int i = 0; i < N; i++ ) {106 for( int i = 0; TEST(i < N); i++ ) { 103 107 wait( condAB , globalA, globalB ); 108 KICK_WATCHDOG; 104 109 } 105 110 … … 110 115 // Waiter AC 111 116 void main( WaiterAC & this ) { 112 for( int i = 0; i < N; i++ ) {117 for( int i = 0; TEST(i < N); i++ ) { 113 118 wait( condAC , globalA, globalC ); 119 KICK_WATCHDOG; 114 120 } 115 121 … … 120 126 // Waiter BC 121 127 void main( WaiterBC & this ) { 122 for( int i = 0; i < N; i++ ) {128 for( int i = 0; TEST(i < N); i++ ) { 123 129 wait( condBC , globalB, globalC ); 130 KICK_WATCHDOG; 124 131 } 125 132 … … 133 140 waiter_left = 4; 134 141 processor p[2]; 135 sout | "Starting" | endl;142 sout | "Starting"; 136 143 { 137 144 Signaler e; … … 143 150 } 144 151 } 145 sout | "Done" | endl;152 sout | "Done"; 146 153 } -
tests/concurrent/thread.cfa
r7951100 rb067d9b 1 #include <fstream >2 #include <kernel >3 #include <stdlib >4 #include <thread >1 #include <fstream.hfa> 2 #include <kernel.hfa> 3 #include <stdlib.hfa> 4 #include <thread.hfa> 5 5 6 6 thread First { semaphore* lock; }; … … 12 12 void main(First& this) { 13 13 for(int i = 0; i < 10; i++) { 14 sout | "First : Suspend No." | i + 1 | endl;14 sout | "First : Suspend No." | i + 1; 15 15 yield(); 16 16 } … … 21 21 P(*this.lock); 22 22 for(int i = 0; i < 10; i++) { 23 sout | "Second : Suspend No." | i + 1 | endl;23 sout | "Second : Suspend No." | i + 1; 24 24 yield(); 25 25 } … … 29 29 int main(int argc, char* argv[]) { 30 30 semaphore lock = { 0 }; 31 sout | "User main begin" | endl;31 sout | "User main begin"; 32 32 { 33 33 processor p; … … 37 37 } 38 38 } 39 sout | "User main end" | endl;39 sout | "User main end"; 40 40 } -
tests/concurrent/waitfor/barge.cfa
r7951100 rb067d9b 6 6 //--------------------------------------------------------- 7 7 8 #include <fstream >9 #include <kernel >10 #include <monitor >11 #include <stdlib >12 #include <thread >8 #include <fstream.hfa> 9 #include <kernel.hfa> 10 #include <monitor.hfa> 11 #include <stdlib.hfa> 12 #include <thread.hfa> 13 13 14 14 #include <stdbool.h> … … 48 48 yield(random( 10 )); 49 49 if( this.state != WAITFOR && !this.done && this.started ) { 50 serr | "Barging before caller detected" | endl;50 serr | "Barging before caller detected"; 51 51 } 52 52 … … 66 66 this.state = WAITFOR; 67 67 waitfor(do_call, this) { 68 sout | i | endl;68 sout | i; 69 69 } 70 70 71 71 if( this.state != CALL ) { 72 serr | "Barging after caller detected" | endl;72 serr | "Barging after caller detected"; 73 73 } 74 74 } … … 83 83 84 84 int main() { 85 sout | "Starting" | endl;85 sout | "Starting"; 86 86 { 87 87 barger_t bargers[17]; … … 89 89 waiter_t waiters; 90 90 } 91 sout | "Stopping" | endl;91 sout | "Stopping"; 92 92 } -
tests/concurrent/waitfor/dtor.cfa
r7951100 rb067d9b 4 4 //--------------------------------------------------------- 5 5 6 #include <fstream >7 #include <kernel >8 #include <monitor >9 #include <stdlib >10 #include <thread >6 #include <fstream.hfa> 7 #include <kernel.hfa> 8 #include <monitor.hfa> 9 #include <stdlib.hfa> 10 #include <thread.hfa> 11 11 12 12 #include <stdbool.h> … … 29 29 switch(state) { 30 30 case CTOR : break; 31 case MAIN : if( this.state != CTOR ) { serr | "ERROR Expected state to be CTOR" | endl; abort(); } this.state = state; break;32 case AFTER : if( this.state != MAIN ) { serr | "ERROR Expected state to be MAIN" | endl; abort(); } this.state = state; break;33 case END : if( this.state != AFTER ) { serr | "ERROR Expected state to be AFTER" | endl; abort(); } this.state = state; break;34 case DTOR : if( this.state != END ) { serr | "ERROR Expected state to be END" | endl; abort(); } this.state = state; break;31 case MAIN : if( this.state != CTOR ) { serr | "ERROR Expected state to be CTOR" ; abort(); } this.state = state; break; 32 case AFTER : if( this.state != MAIN ) { serr | "ERROR Expected state to be MAIN" ; abort(); } this.state = state; break; 33 case END : if( this.state != AFTER ) { serr | "ERROR Expected state to be AFTER"; abort(); } this.state = state; break; 34 case DTOR : if( this.state != END ) { serr | "ERROR Expected state to be END" ; abort(); } this.state = state; break; 35 35 } 36 36 } … … 54 54 55 55 int main() { 56 sout | "Starting" | endl;56 sout | "Starting"; 57 57 processor p; 58 58 for( int i = 0; i < N; i++ ){ … … 60 60 yield( random( 100 ) ); 61 61 } 62 sout | "Stopping" | endl;62 sout | "Stopping"; 63 63 } -
tests/concurrent/waitfor/else.cfa
r7951100 rb067d9b 1 #include <fstream >2 #include <monitor >1 #include <fstream.hfa> 2 #include <monitor.hfa> 3 3 4 4 #include <stdbool.h> … … 12 12 void test( M & mutex m ) { 13 13 int i = 0; 14 sout | "Starting" | endl;14 sout | "Starting"; 15 15 16 16 when( false ) waitfor( notcalled, m ); 17 17 18 sout | "Step" | i++ | endl;18 sout | "Step" | i++; 19 19 20 20 waitfor( notcalled, m ); or else { 21 sout | "else called" | endl;21 sout | "else called"; 22 22 } 23 23 24 sout | "Step" | i++ | endl;24 sout | "Step" | i++; 25 25 26 26 when( true ) waitfor( notcalled, m ); or when( true ) else { 27 sout | "else called" | endl;27 sout | "else called"; 28 28 } 29 29 30 sout | "Step" | i++ | endl;30 sout | "Step" | i++; 31 31 32 32 when( false ) waitfor( notcalled, m ); or when( true ) else { 33 sout | "else called" | endl;33 sout | "else called"; 34 34 } 35 35 36 sout | "Step" | i++ | endl;36 sout | "Step" | i++; 37 37 38 38 when( false ) waitfor( notcalled, m ); or when( false ) else { 39 sout | "else called" | endl;39 sout | "else called"; 40 40 } 41 41 42 sout | "Done" | endl;42 sout | "Done"; 43 43 } 44 44 -
tests/concurrent/waitfor/parse.cfa
r7951100 rb067d9b 8 8 //---------------------------------------------------------------------------------------- 9 9 10 #include <monitor >10 #include <monitor.hfa> 11 11 12 12 monitor M {}; -
tests/concurrent/waitfor/parse2.cfa
r7951100 rb067d9b 10 10 // Created On : Wed Aug 30 17:53:29 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 30 17:55:17 201713 // Update Count : 212 // Last Modified On : Fri Mar 22 13:42:11 2019 13 // Update Count : 3 14 14 // 15 15 … … 246 246 // Local Variables: // 247 247 // tab-width: 4 // 248 // compile-command: "cfa waitfor.c " //248 // compile-command: "cfa waitfor.cfa" // 249 249 // End: // -
tests/concurrent/waitfor/recurse.cfa
r7951100 rb067d9b 4 4 //----------------------------------------------------------------- 5 5 6 #include <fstream >7 #include <kernel >8 #include <monitor >9 #include <stdlib >10 #include <thread >6 #include <fstream.hfa> 7 #include <kernel.hfa> 8 #include <monitor.hfa> 9 #include <stdlib.hfa> 10 #include <thread.hfa> 11 11 12 12 #include <stdbool.h> … … 95 95 rand_yield(); 96 96 97 sout | "1st" | endl;97 sout | "1st" | nl; 98 98 99 99 return this.counter < N ? (state_t)this.actions[idx] : (state_t)STOP; … … 123 123 case THIRD : while( !global.ready ) { yield(); } this.state = call3( global, this.idx ); break; 124 124 case LAST : while( !global.ready ) { yield(); } this.state = call4( global, this.idx ); break; 125 case STOP : serr | "This should not happen" | endl;125 case STOP : serr | "This should not happen" | nl; 126 126 } 127 127 } … … 132 132 int main() { 133 133 srandom( time(NULL) ); 134 sout | "Starting" | endl; 134 sout | nlOff; // turn off auto newline 135 sout | "Starting" | nl; 135 136 { 136 137 waiter_t waiters[4] = { … … 142 143 the_threads = waiters; 143 144 } 144 sout | "Stopping" | endl;145 sout | "Stopping" | nl; 145 146 } -
tests/concurrent/waitfor/simple.cfa
r7951100 rb067d9b 1 #include <fstream >2 #include <kernel >3 #include <monitor >4 #include <stdlib >5 #include <thread >1 #include <fstream.hfa> 2 #include <kernel.hfa> 3 #include <monitor.hfa> 4 #include <stdlib.hfa> 5 #include <thread.hfa> 6 6 7 7 #include <time.h> … … 31 31 32 32 void do_wait( global_t * mutex a ) { 33 sout | "Waiting to accept" | endl;33 sout | "Waiting to accept"; 34 34 yield( random( 10 ) ); 35 35 36 sout | "Accepting" | endl;36 sout | "Accepting"; 37 37 38 38 __acceptable_t acceptable; … … 43 43 __waitfor_internal( 1, &acceptable ); 44 44 45 sout | "Accepted" | endl;45 sout | "Accepted"; 46 46 yield( random( 10 ) ); 47 47 } … … 50 50 for( int i = 0; i < N; i++ ) { 51 51 do_wait( &globalA ); 52 sout | i | endl;52 sout | i; 53 53 } 54 54 … … 76 76 srandom( time( NULL ) ); 77 77 printf("%p\n", &globalA); 78 sout | "Starting" | endl;78 sout | "Starting"; 79 79 { 80 80 Acceptor r; … … 82 82 83 83 } 84 sout | "Done" | endl;84 sout | "Done"; 85 85 } -
tests/concurrent/waitfor/statment.cfa
r7951100 rb067d9b 1 #include <fstream >2 #include <kernel >3 #include <monitor >4 #include <thread >1 #include <fstream.hfa> 2 #include <kernel.hfa> 3 #include <monitor.hfa> 4 #include <thread.hfa> 5 5 6 6 #include <stdbool.h> … … 84 84 case 7: return call7( m ); 85 85 default : 86 serr | "Incorrect index" | index | endl;86 serr | "Incorrect index" | index; 87 87 abort(); 88 88 } … … 102 102 while( !done ) { 103 103 waitfor( get_index, this ); 104 or waitfor( call1, this ) { sout | "Statement" | endl; if( this.last_val != 1 ) { serr | "Incorrect index: expected" | 1 | "got" | this.last_val | endl; } }105 or waitfor( call2, this ) { sout | "Statement" | endl; if( this.last_val != 2 ) { serr | "Incorrect index: expected" | 2 | "got" | this.last_val | endl; } }106 or waitfor( call3, this ) { sout | "Statement" | endl; if( this.last_val != 3 ) { serr | "Incorrect index: expected" | 3 | "got" | this.last_val | endl; } }107 or waitfor( call4, this ) { sout | "Statement" | endl; if( this.last_val != 4 ) { serr | "Incorrect index: expected" | 4 | "got" | this.last_val | endl; } }108 or waitfor( call5, this ) { sout | "Statement" | endl; if( this.last_val != 5 ) { serr | "Incorrect index: expected" | 5 | "got" | this.last_val | endl; } }109 or waitfor( call6, this ) { sout | "Statement" | endl; if( this.last_val != 6 ) { serr | "Incorrect index: expected" | 6 | "got" | this.last_val | endl; } }110 or waitfor( call7, this ) { sout | "Statement" | endl; if( this.last_val != 7 ) { serr | "Incorrect index: expected" | 7 | "got" | this.last_val | endl; } }104 or waitfor( call1, this ) { sout | "Statement"; if( this.last_val != 1 ) { serr | "Incorrect index: expected" | 1 | "got" | this.last_val; } } 105 or waitfor( call2, this ) { sout | "Statement"; if( this.last_val != 2 ) { serr | "Incorrect index: expected" | 2 | "got" | this.last_val; } } 106 or waitfor( call3, this ) { sout | "Statement"; if( this.last_val != 3 ) { serr | "Incorrect index: expected" | 3 | "got" | this.last_val; } } 107 or waitfor( call4, this ) { sout | "Statement"; if( this.last_val != 4 ) { serr | "Incorrect index: expected" | 4 | "got" | this.last_val; } } 108 or waitfor( call5, this ) { sout | "Statement"; if( this.last_val != 5 ) { serr | "Incorrect index: expected" | 5 | "got" | this.last_val; } } 109 or waitfor( call6, this ) { sout | "Statement"; if( this.last_val != 6 ) { serr | "Incorrect index: expected" | 6 | "got" | this.last_val; } } 110 or waitfor( call7, this ) { sout | "Statement"; if( this.last_val != 7 ) { serr | "Incorrect index: expected" | 7 | "got" | this.last_val; } } 111 111 112 112 done = true; … … 128 128 int main() { 129 129 processor p[2]; 130 sout | "Starting" | endl;130 sout | "Starting"; 131 131 { 132 132 caller c[7]; 133 133 waiter w; 134 134 } 135 sout | "Stopping" | endl;135 sout | "Stopping"; 136 136 } -
tests/concurrent/waitfor/when.cfa
r7951100 rb067d9b 4 4 //----------------------------------------------------------------- 5 5 6 #include <fstream >7 #include <kernel >8 #include <monitor >9 #include <stdlib >10 #include <thread >6 #include <fstream.hfa> 7 #include <kernel.hfa> 8 #include <monitor.hfa> 9 #include <stdlib.hfa> 10 #include <thread.hfa> 11 11 12 12 #include <stdbool.h> … … 58 58 void arbiter( global_t & mutex this ) { 59 59 for( int i = 0; i < N; i++ ) { 60 when( this.last_call == 6 ) waitfor( call1, this ) { if( this.last_call != 1) { serr | "Expected last_call to be 1 got" | this.last_call | endl; } }61 or when( this.last_call == 1 ) waitfor( call2, this ) { if( this.last_call != 2) { serr | "Expected last_call to be 2 got" | this.last_call | endl; } }62 or when( this.last_call == 2 ) waitfor( call3, this ) { if( this.last_call != 3) { serr | "Expected last_call to be 3 got" | this.last_call | endl; } }63 or when( this.last_call == 3 ) waitfor( call4, this ) { if( this.last_call != 4) { serr | "Expected last_call to be 4 got" | this.last_call | endl; } }64 or when( this.last_call == 4 ) waitfor( call5, this ) { if( this.last_call != 5) { serr | "Expected last_call to be 5 got" | this.last_call | endl; } }65 or when( this.last_call == 5 ) waitfor( call6, this ) { if( this.last_call != 6) { serr | "Expected last_call to be 6 got" | this.last_call | endl; } }60 when( this.last_call == 6 ) waitfor( call1, this ) { if( this.last_call != 1) { serr | "Expected last_call to be 1 got" | this.last_call; } } 61 or when( this.last_call == 1 ) waitfor( call2, this ) { if( this.last_call != 2) { serr | "Expected last_call to be 2 got" | this.last_call; } } 62 or when( this.last_call == 2 ) waitfor( call3, this ) { if( this.last_call != 3) { serr | "Expected last_call to be 3 got" | this.last_call; } } 63 or when( this.last_call == 3 ) waitfor( call4, this ) { if( this.last_call != 4) { serr | "Expected last_call to be 4 got" | this.last_call; } } 64 or when( this.last_call == 4 ) waitfor( call5, this ) { if( this.last_call != 5) { serr | "Expected last_call to be 5 got" | this.last_call; } } 65 or when( this.last_call == 5 ) waitfor( call6, this ) { if( this.last_call != 6) { serr | "Expected last_call to be 6 got" | this.last_call; } } 66 66 67 sout | this.last_call | endl;67 sout | this.last_call; 68 68 } 69 69 … … 78 78 int main() { 79 79 srandom( time(NULL) ); 80 sout | "Starting" | endl;80 sout | "Starting"; 81 81 { 82 82 arbiter_t arbiter; … … 84 84 85 85 } 86 sout | "Stopping" | endl;86 sout | "Stopping"; 87 87 }
Note:
See TracChangeset
for help on using the changeset viewer.