Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrent/futures/multi.cfa

    re2cc3c7 r44e37ef  
    55
    66thread Server {
    7         int pending, done, iteration;
     7        int cnt, iteration;
    88        multi_future(int) * request;
    99};
    1010
    1111void ?{}( Server & this ) {
    12         ((thread&)this){"Server Thread"};
    13         this.pending = 0;
    14         this.done = 0;
     12        this.cnt = 0;
    1513        this.iteration = 0;
    1614        this.request = 0p;
     
    1816
    1917void ^?{}( Server & mutex this ) {
    20         assert(this.pending == 0);
    21         this.request = 0p;
     18        assert(this.cnt == 0);
     19    this.request = 0p;
    2220}
    2321
     
    2624}
    2725
    28 void call( Server & mutex this ) {
    29         this.pending++;
     26void process( Server & mutex this ) {
     27        fulfil( *this.request, this.iteration );
     28        this.iteration++;
    3029}
    3130
    32 void finish( Server & mutex this ) {
    33         this.done++;
     31void call( Server & mutex this ) {
     32        this.cnt++;
    3433}
    3534
     35void finish( Server & mutex this ) { }
     36
    3637void main( Server & this ) {
    37         MAIN_LOOP:
    3838        for() {
    3939                waitfor( ^?{} : this ) {
    4040                        break;
    4141                }
    42                 or waitfor( call: this ) {
    43                         if (this.pending != NFUTURES) { continue MAIN_LOOP; }
    44 
    45                         this.pending = 0;
    46                         fulfil( *this.request, this.iteration );
    47                         this.iteration++;
    48 
    49                         for(NFUTURES) {
    50                                 waitfor( finish: this );
     42                or when( this.cnt < NFUTURES ) waitfor( call: this ) {
     43                        if (this.cnt == NFUTURES) {
     44                                process(this);
    5145                        }
    52 
    53                         reset( *this.request );
    54                         this.done = 0;
     46                }
     47                or waitfor( finish: this ) {
     48                        if (this.cnt == NFUTURES) {
     49                                reset( *this.request );
     50                                this.cnt = 0;
     51                        }
    5552                }
    5653        }
     
    6057Server * the_server;
    6158thread Worker {};
    62 void ?{}(Worker & this) {
    63         ((thread&)this){"Worker Thread"};
    64 }
    65 
    6659multi_future(int) * shared_future;
    6760
Note: See TracChangeset for help on using the changeset viewer.