source: tests/concurrency/waituntil/one_chan.cfa @ 1571e4d

Last change on this file since 1571e4d was cb344f7, checked in by caparsons <caparson@…>, 16 months ago

refactored tests to use new syntax for channel ops

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