#include #include enum {NFUTURES = 10}; thread Server { int cnt, iteration; multi_future(int) * request; }; void ?{}( Server & this ) { ((thread&)this){"Server Thread"}; this.cnt = 0; this.iteration = 0; this.request = 0p; } void ^?{}( Server & mutex this ) { assert(this.cnt == 0); this.request = 0p; } void init( Server & this , multi_future(int) * f ) { this.request = f; } void process( Server & mutex this ) { fulfil( *this.request, this.iteration ); this.iteration++; } void call( Server & mutex this ) { this.cnt++; } void finish( Server & mutex this ) { } void main( Server & this ) { for() { waitfor( ^?{} : this ) { break; } or when( this.cnt < NFUTURES ) waitfor( call: this ) { if (this.cnt == NFUTURES) { process(this); } } or waitfor( finish: this ) { if (this.cnt == NFUTURES) { reset( *this.request ); this.cnt = 0; } } } } Server * the_server; thread Worker {}; void ?{}(Worker & this) { ((thread&)this){"Worker Thread"}; } multi_future(int) * shared_future; void thrash(void) { volatile int locals[250]; for(i; 250) { locals[i] = 0xdeadbeef; } } void work(int num) { call( *the_server ); int res = wait( *shared_future ); if( res != num ) abort(); finish( *the_server ); } void main( Worker & ) { for (i; 10) { thrash(); work(i); thrash(); } } int main() { printf( "start\n" ); // non-empty .expect file processor procs[2]; shared_future = new(); { Server server; the_server = &server; init(server, shared_future); { Worker workers[NFUTURES]; } } delete( shared_future ); printf( "done\n" ); // non-empty .expect file }