Changeset ec22220
- Timestamp:
- Dec 10, 2024, 3:07:59 PM (8 days ago)
- Branches:
- master
- Children:
- 64f3b9f
- Parents:
- 6e6e372
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrency/waituntil/channel_close.cfa
r6e6e372 rec22220 1 #include < select.hfa>1 #include <fstream.hfa> 2 2 #include <thread.hfa> 3 3 #include <channel.hfa> 4 4 #include <time.hfa> 5 5 6 channel( long long int) A, B;6 channel(ssize_t) A, B; 7 7 8 volatile long long int inserts = 0; 9 volatile long long int removes = 0; 8 volatile size_t inserts = 0, removes = 0; 10 9 11 10 thread Producer {}; 12 11 void main( Producer & this ) { 13 12 try { 14 for( long long int i = 0;;i++) {13 for( size_t i; 0~@ ) { 15 14 waituntil( A << i ) { inserts++; } 16 15 and waituntil( B << i ) { inserts++; } … … 22 21 thread Consumer {}; // ensures that the changing when states of Server1 don't result in a deadlock 23 22 void main( Consumer & this ) { 24 long long int in, in2, A_removes = 0, B_removes = 0; 23 ssize_t in, in2, A_removes = 0, B_removes = 0; 24 25 25 try { 26 for ( ;;) {26 for () { 27 27 if ( useAnd ) { 28 28 waituntil( (in << A) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( A_removes == in ); A_removes++; removes++; } … … 33 33 or waituntil( (in << B) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); ( B_removes == in ); B_removes++; removes++; } 34 34 } 35 } catchResume ( channel_closed * e ) {} // continue to remove until would block 36 catch ( channel_closed * e ) {} 35 } catchResume ( channel_closed * e ) { // continue to remove until would block 36 } catch ( channel_closed * e ) {} 37 37 38 try { 38 for ( ;;)39 for () 39 40 waituntil( (in << A) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( A_removes == in ); A_removes++; removes++; } 40 } catchResume ( channel_closed * e ) {} // continue to remove until would block 41 catch ( channel_closed * e ) {} 41 } catchResume ( channel_closed * e ) { // continue to remove until would block 42 } catch ( channel_closed * e ) {} 43 42 44 try { 43 for ( ;;)45 for () 44 46 waituntil( (in << B) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( B_removes == in ); B_removes++; removes++; } 45 } catchResume ( channel_closed * e ) { }// continue to remove until would block46 47 } catchResume ( channel_closed * e ) { // continue to remove until would block 48 } catch ( channel_closed * e ) {} 47 49 } 48 50 51 int main( int argc, char * argv[] ) { 52 size_t time = 5; 49 53 50 size_t time = 5;51 int main( int argc, char * argv[] ) {52 54 if ( argc == 2 ) 53 55 time = atoi( argv[1] ); … … 57 59 B{5}; 58 60 59 printf("start OR\n");61 sout | "start OR"; 60 62 { 61 63 Producer p; 62 64 Consumer c; 63 65 sleep(time`s); 64 printf("done sleep\n");65 printf("closing A\n");66 close( A);67 printf("closing B\n");68 close( B);66 sout | "done sleep"; 67 sout | "closing A"; 68 close( A ); 69 sout | "closing B"; 70 close( B ); 69 71 } 70 72 if ( inserts != removes ) 71 printf("CHECKSUM MISMATCH!! Producer got: %lld, Consumer got: %lld\n", inserts, removes);72 printf("done\n");73 sout | "CHECKSUM MISMATCH!! Producer got:" | inserts | ", Consumer got:" | removes; 74 sout | "done"; 73 75 ^A{}; 74 76 ^B{}; 75 77 76 78 useAnd = true; 77 78 inserts = 0; 79 removes = 0; 79 inserts = removes = 0; 80 80 A{5}; 81 81 B{5}; 82 printf("start AND\n");82 sout | "start AND"; 83 83 { 84 84 Producer p; 85 85 Consumer c; 86 sleep( time`s);87 printf("done sleep\n");88 printf("closing A\n");89 close( A);90 printf("closing B\n");91 close( B);86 sleep( time`s ); 87 sout | "done sleep"; 88 sout | "closing A"; 89 close( A ); 90 sout | "closing B"; 91 close( B ); 92 92 } 93 93 if ( inserts != removes ) 94 printf("CHECKSUM MISMATCH!! Producer got: %lld, Consumer got: %lld\n", inserts, removes);95 printf("done\n");94 sout | "CHECKSUM MISMATCH!! Producer got:" | inserts | ", Consumer got:" | removes; 95 sout | "done"; 96 96 }
Note: See TracChangeset
for help on using the changeset viewer.