Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/waituntil/futures.cfa

    rb5749f9 rd923fca6  
    1 #include <fstream.hfa>
     1#include <select.hfa>
    22#include <future.hfa>
    33#include <thread.hfa>
     
    55future(int) A, B, C;
    66
    7 thread Server {};
    8 void main( Server & ) {
    9         B( 3 ); // fulfil( B, 3 );
    10         A( 2 );
    11         C( 4 );
     7semaphore s{0};
     8
     9thread Server1 {};
     10void main( Server1 & ) {
     11    fulfil(B, 3);
     12    P( s );
     13    fulfil(A, 2);
     14    fulfil(C, 4);
     15}
     16
     17thread Server2 {};
     18void main( Server2 & ) {
     19    fulfil(B, 6);
     20    fulfil(A, 5);
     21    fulfil(C, 7);
    1222}
    1323
    1424int main() {
    15         processor p;
    16     sout | "start";
    17         {
    18                 size_t count = 0;
    19                 Server s;
    20                 for ( ; count < 3; ) {
    21                         waituntil( A ) { count += 1; A(); /* get( A ) */ }
    22                         or waituntil( B ) { count += 1; B(); }
    23                         or waituntil( C ) { count += 1; C(); }
    24                 }
    25                 reset( A ); reset( B ); reset( C );
    26         }
    27         {
    28                 size_t count = 0;
    29                 Server s;
    30                 for ( ; count < 3; ) {
    31                         waituntil( A ) { count += 1; A(); /* get( A ) */ }
    32                         or waituntil( B ) { count += 1; B(); }
    33                         and waituntil( C ) { count += 1; C(); }
    34                 }
    35                 reset( A ); reset( B ); reset( C );
    36         }
    37         size_t count = 0;
    38         for ( i; 8 ) {
    39                 {
    40                         Server s;
    41                         when( i % 2 == 0 ) waituntil( A ) { count += 1; A(); }
    42                         or when( i % 4 < 2 ) waituntil( B ) { count += 1; B(); }
    43                         and when( i < 4 ) waituntil( C ) { count += 1; C(); }
    44                 }
    45                 reset( A ); reset( B ); reset( C );
    46                 {
    47                         Server s;
    48                         ( when( i % 2 == 0 ) waituntil( A ) { count += 1; A(); }
    49                           or when( i % 4 < 2 ) waituntil( B ) { count += 1; B(); }
    50                         ) and when( i < 4 ) waituntil( C ) { count += 1; C(); }
    51                 }
    52                 reset( A ); reset( B ); reset( C );
    53         } // for
    54         sout | "end";
     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;
    5561}
Note: See TracChangeset for help on using the changeset viewer.