source: tests/concurrency/waituntil/futures.cfa @ ffac259

Last change on this file since ffac259 was c26bea2a, checked in by Peter A. Buhr <pabuhr@…>, 18 months ago

first attempt at renaming directory tests/concurrent to tests/concurrency to harmonize with other concurrency directory names

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <select.hfa>
2#include <future.hfa>
3#include <thread.hfa>
4
5future(int) A, B, C;
6
7semaphore s{0};
8
9thread Server1 {};
10void main( Server1 & this ) {
11    fulfil(B, 3);
12    P( s );
13    fulfil(A, 2);
14    fulfil(C, 4);
15}
16
17thread Server2 {};
18void main( Server2 & this ) {
19    fulfil(B, 6);
20    fulfil(A, 5);
21    fulfil(C, 7);
22}
23
24int main() {
25    processor proc[1];
26    printf("start\n"); // currently not working
27    {
28        Server1 s1;
29        waituntil( A ) { get(A); }
30        or waituntil( B ) { get(B); V( s ); }
31        and waituntil( C ) { get(C); }
32    }
33    reset(A);
34    reset(B);
35    reset(C);
36    for ( int i = 0; i < 8; i++ ) {
37        {
38            Server2 s2;
39            when( i % 2 == 0 ) waituntil( A ) { get(A); }
40            or when( i % 4 < 2 ) waituntil( B ) { get(B); }
41            and when( i < 4 ) waituntil( C ) { get(C); }
42        }
43        reset(A);
44        reset(B);
45        reset(C);
46        {
47            Server2 s2;
48            (
49                when( i % 2 == 0 ) waituntil( A ) { get(A); }
50                or when( i % 4 < 2 ) waituntil( B ) { get(B); }
51            )
52            and when( i < 4 ) waituntil( C ) { get(C); }
53        }
54        reset(A);
55        reset(B);
56        reset(C);
57    }
58
59    printf("end\n");
60    return 0;
61}
Note: See TracBrowser for help on using the repository browser.