source: tests/concurrent/waituntil/channels-no-when.cfa @ 85e49a6

ADTast-experimental
Last change on this file since 85e49a6 was dd7a8ce, checked in by caparsons <caparson@…>, 18 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: 2.2 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
22thread Churner {}; // performs non-waituntil try insert/remove operations to add churn/interference
23void main( Churner & this ) {
24    long long int out, myTotal = 0;
25    bool success;
26    while( !done ) {
27        try_insert( A, 0 );
28        try_insert( B, 0 );
29        try_insert( C, 0 );
30        [out, success] = try_remove( A );
31        if ( success ) myTotal += out;
32        [out, success] = try_remove( B );
33        if ( success ) myTotal += out;
34        [out, success] = try_remove( C );
35        if ( success ) myTotal += out;
36    }
37    __atomic_fetch_add( &globalTotal, myTotal, __ATOMIC_SEQ_CST );
38}
39
40size_t numtimes = 100000;
41size_t numServers = 3;
42int main( int argc, char * argv[] ) {
43    if ( argc == 2 )
44        numtimes = atoi( argv[1] );
45
46    processor p[numServers + 1];
47    A{5};
48    B{5};
49    C{5};
50
51    long long int total = 0;
52    printf("start\n");
53    {
54        Server1 s[numServers];
55        {
56            Churner c;
57            for( long long int j = 0; j < numtimes; j++ ) {
58                waituntil( j >> A ) { total += j; }
59                or waituntil( j >> B ) { total += j; }
60                and waituntil( j >> C ) { total += j; }
61            }
62            done = true;
63            printf("terminating churner\n");
64        }
65        printf("waiting for empty channels\n");
66        while( get_count( A ) > 0 || get_count( B ) > 0 || get_count( C ) > 0 ) { }
67        printf("sending sentinels\n");
68        for ( i; numServers ) insert( C, -1 );
69        printf("joining servers\n");
70    }
71    if ( total != globalTotal )
72        printf("CHECKSUM MISMATCH!! Main thread got %lld, server sum is %lld\n", total, globalTotal);
73    printf("done\n");
74}
Note: See TracBrowser for help on using the repository browser.