source: tests/concurrency/waituntil/channel_close.cfa @ c17dc80

Last change on this file since c17dc80 was cbbfba9, checked in by caparsons <caparson@…>, 8 months ago

added fence to failing test to hopefully fix stale data issue on the arm, if this passes this fence will be put in waituntil code gen

  • Property mode set to 100644
File size: 2.9 KB
Line 
1#include <select.hfa>
2#include <thread.hfa>
3#include <channel.hfa>
4#include <time.hfa>
5
6channel(long long int) A, B;
7
8volatile long long int inserts = 0;
9volatile long long int removes = 0;
10
11thread Producer {};
12void main( Producer & this ) {
13    try {
14        for( long long int i = 0;;i++ ) {
15            waituntil( A << i ) { inserts++; }
16            and waituntil( B << i ) { inserts++; }
17        }
18    } catch ( channel_closed * e ) {}
19}
20
21bool useAnd = false;
22thread Consumer {}; // ensures that the changing when states of Server1 don't result in a deadlock
23void main( Consumer & this ) {
24    long long int in, in2, A_removes = 0, B_removes = 0;
25    try {
26        for( ;; ) {
27            if ( useAnd ) {
28                waituntil( (in << A) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( A_removes == in ); A_removes++; removes++; }
29                and waituntil( (in2 << B) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( B_removes == in2 ); B_removes++; removes++; }
30                continue;
31            }
32            waituntil( (in << A) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( A_removes == in ); A_removes++; removes++; }
33            or waituntil( (in << B) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); ( B_removes == in ); B_removes++; removes++; }
34        }
35    } catchResume ( channel_closed * e ) {} // continue to remove until would block
36    catch ( channel_closed * e ) {}
37    try {
38        for( ;; )
39            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 ) {}
42    try {
43        for( ;; )
44            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 block
46    catch ( channel_closed * e ) {}
47}
48
49
50size_t time = 5;
51int main( int argc, char * argv[] ) {
52    if ( argc == 2 )
53        time = atoi( argv[1] );
54
55    processor p[2];
56    A{5};
57    B{5};
58
59    printf("start OR\n");
60    {
61        Producer p;
62        Consumer c;
63        sleep(time`s);
64        printf("done sleep\n");
65        printf("closing A\n");
66        close(A);
67        printf("closing B\n");
68        close(B);
69    }
70    if ( inserts != removes )
71        printf("CHECKSUM MISMATCH!! Producer got: %lld, Consumer got: %lld\n", inserts, removes);
72    printf("done\n");
73    ^A{};
74    ^B{};
75
76    useAnd = true;
77
78    inserts = 0;
79    removes = 0;
80    A{5};
81    B{5};
82    printf("start AND\n");
83    {
84        Producer p;
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);
92    }
93    if ( inserts != removes )
94        printf("CHECKSUM MISMATCH!! Producer got: %lld, Consumer got: %lld\n", inserts, removes);
95    printf("done\n");
96}
Note: See TracBrowser for help on using the repository browser.