Changeset 00aa122 for tests/concurrency/futures/typed.cfa
- Timestamp:
- Nov 24, 2025, 4:13:37 PM (17 hours ago)
- Branches:
- master
- Parents:
- fbaea970
- File:
-
- 1 edited
-
tests/concurrency/futures/typed.cfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrency/futures/typed.cfa
rfbaea970 r00aa122 8 8 }; 9 9 10 void ?{}( Server & this) {11 this.cnt = 0;12 for (i; NFUTURES) {13 this.requests[i] = 0p;10 void ?{}( Server & server ) with( server ) { 11 cnt = 0; 12 for ( i; NFUTURES ) { 13 requests[i] = 0p; 14 14 } 15 15 } 16 16 17 void ^?{}( Server & mutex this ){18 assert( this.cnt == 0);19 for (i; NFUTURES) {20 this.requests[i] = 0p;17 void ^?{}( Server & mutex server ) with( server ) { 18 assert( cnt == 0 ); 19 for ( i; NFUTURES ) { 20 requests[i] = 0p; 21 21 } 22 22 } 23 23 24 void process( Server & this, int i ){25 if( this.requests[i] == 0p ) return;26 single_future(int) * f = this.requests[i];27 this.requests[i] = 0p;28 this.cnt--;29 fulfil( *f , i);24 void process( Server & server, int i ) with( server ) { 25 if ( requests[i] == 0p ) return; 26 single_future(int) * f = requests[i]; 27 requests[i] = 0p; 28 cnt--; 29 (*f)( i ); // fulfil 30 30 } 31 31 32 void call( Server & mutex this, single_future(int) & f) {33 for (i; NFUTURES) {34 if ( this.requests[i] == 0p ) {35 this.requests[i] = &f;36 this.cnt++;32 void call( Server & mutex server, single_future(int) & f ) with( server ) { 33 for ( i; NFUTURES ) { 34 if ( requests[i] == 0p ) { 35 requests[i] = &f; 36 cnt++; 37 37 return; 38 38 } … … 41 41 } 42 42 43 void main( Server & this) {43 void main( Server & server ) { 44 44 unsigned i = 0; 45 for () {46 waitfor ( ^?{} : this) {45 for () { 46 waitfor ( ^?{} : server ) { 47 47 break; 48 } 49 or when( this.cnt < NFUTURES ) waitfor( call: this ) {} 48 } or when( server.cnt < NFUTURES ) waitfor( call : server ) {} 50 49 or else { 51 process( this, i % NFUTURES );50 process( server, i % NFUTURES ); 52 51 i++; 53 52 } 54 53 } 55 54 56 for (i; NFUTURES) {57 process( this, i );55 for ( i; NFUTURES ) { 56 process( server, i ); 58 57 } 59 58 } … … 62 61 thread Worker {}; 63 62 64 void thrash( void) {63 void thrash() { 65 64 volatile int locals[250]; 66 for (i; 250) {65 for ( i; 250 ) { 67 66 locals[i] = 0xdeadbeef; 68 67 } 69 68 } 70 69 71 void work( void) {70 void work() { 72 71 single_future(int) mine; 73 72 call( *the_server, mine ); 74 wait( mine );73 mine(); // get 75 74 } 76 75 77 76 void main( Worker & ) { 78 for (150) {77 for ( 150 ) { 79 78 thrash(); 80 79 work(); … … 84 83 85 84 int main() { 86 printf( "start\n" ); // non-empty .expect file85 printf( "start\n" ); // non-empty .expect file 87 86 processor procs[2]; 88 87 { … … 93 92 } 94 93 } 95 printf( "done\n" ); // non-empty .expect file 96 94 printf( "done\n" ); // non-empty .expect file 97 95 }
Note:
See TracChangeset
for help on using the changeset viewer.