source: tests/concurrent/waituntil/channels-SPSC.cfa @ dd7a8ce

ADTast-experimental
Last change on this file since dd7a8ce was dd7a8ce, checked in by caparsons <caparson@…>, 14 months ago

added some variations on failing channel test to try and narrow down failure to minimal case. Window for deadlock must be small as it seems to be irreproducible unless during full build + test.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include <select.hfa>
2#include <thread.hfa>
3#include <channel.hfa>
4
5channel(long long int) A, B, C;
6
7volatile bool done = false;
8long long int globalTotal = 0;
9
10thread Server1 {};
11void main( Server1 & this ) {
12    long long int a, b, c, i = 0, myTotal = 0;
13    for( ;;i++ ) {
14        waituntil( a << A ) { myTotal += a; }
15        or waituntil( b << B ) { myTotal += b; }
16        or waituntil( c << C ) { if ( c == -1 ) break; myTotal += c; }
17        or else {}
18    }
19    __atomic_fetch_add( &globalTotal, myTotal, __ATOMIC_SEQ_CST );
20}
21
22size_t numtimes = 100000;
23size_t numServers = 1;
24int main( int argc, char * argv[] ) {
25    if ( argc == 2 )
26        numtimes = atoi( argv[1] );
27
28    processor p[numServers];
29    A{5};
30    B{5};
31    C{5};
32
33    long long int total = 0;
34    printf("start\n");
35    {
36        Server1 s[numServers];
37        {
38            for( long long int j = 0; j < numtimes; j++ ) {
39                waituntil( j >> A ) { total += j; }
40                or waituntil( j >> B ) { total += j; }
41                and waituntil( j >> C ) { total += j; }
42            }
43        }
44        printf("waiting for empty channels\n");
45        while( get_count( A ) > 0 || get_count( B ) > 0 || get_count( C ) > 0 ) { }
46        printf("sending sentinels\n");
47        for ( i; numServers ) insert( C, -1 );
48        printf("joining servers\n");
49    }
50    if ( total != globalTotal )
51        printf("CHECKSUM MISMATCH!! Main thread got %lld, server sum is %lld\n", total, globalTotal);
52    printf("done\n");
53}
Note: See TracBrowser for help on using the repository browser.