Ignore:
Timestamp:
Nov 24, 2025, 4:13:37 PM (17 hours ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Parents:
fbaea970
Message:

harmonize single_future with other future types, remove multi_future, marks its test as deprecated, and turn off its test

File:
1 edited

Legend:

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

    rfbaea970 r00aa122  
    88};
    99
    10 void ?{}( Server & this ) {
    11         this.cnt = 0;
    12         for(i; NFUTURES) {
    13                 this.requests[i] = 0p;
     10void ?{}( Server & server ) with( server ) {
     11        cnt = 0;
     12        for ( i; NFUTURES ) {
     13                requests[i] = 0p;
    1414        }
    1515}
    1616
    17 void ^?{}( Server & mutex this ) {
    18         assert(this.cnt == 0);
    19         for(i; NFUTURES) {
    20                 this.requests[i] = 0p;
     17void ^?{}( Server & mutex server ) with( server ) {
     18        assert( cnt == 0 );
     19        for ( i; NFUTURES ) {
     20                requests[i] = 0p;
    2121        }
    2222}
    2323
    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);
     24void 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
    3030}
    3131
    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++;
     32void 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++;
    3737                        return;
    3838                }
     
    4141}
    4242
    43 void main( Server & this ) {
     43void main( Server & server ) {
    4444        unsigned i = 0;
    45         for() {
    46                 waitfor( ^?{} : this ) {
     45        for () {
     46                waitfor ( ^?{} : server ) {
    4747                        break;
    48                 }
    49                 or when( this.cnt < NFUTURES ) waitfor( call: this ) {}
     48                } or when( server.cnt < NFUTURES ) waitfor( call : server ) {}
    5049                or else {
    51                         process( this, i % NFUTURES );
     50                        process( server, i % NFUTURES );
    5251                        i++;
    5352                }
    5453        }
    5554
    56         for(i; NFUTURES) {
    57                 process( this, i );
     55        for ( i; NFUTURES ) {
     56                process( server, i );
    5857        }
    5958}
     
    6261thread Worker {};
    6362
    64 void thrash(void) {
     63void thrash() {
    6564        volatile int locals[250];
    66         for(i; 250) {
     65        for ( i; 250 ) {
    6766                locals[i] = 0xdeadbeef;
    6867        }
    6968}
    7069
    71 void work(void) {
     70void work() {
    7271        single_future(int) mine;
    7372        call( *the_server, mine );
    74         wait( mine );
     73        mine();                                                                                         // get
    7574}
    7675
    7776void main( Worker & ) {
    78         for(150) {
     77        for ( 150 ) {
    7978                thrash();
    8079                work();
     
    8483
    8584int main() {
    86         printf( "start\n" );                            // non-empty .expect file
     85        printf( "start\n" );                                                            // non-empty .expect file
    8786        processor procs[2];
    8887        {
     
    9392                }
    9493        }
    95         printf( "done\n" );                             // non-empty .expect file
    96 
     94        printf( "done\n" );                                                                     // non-empty .expect file
    9795}
Note: See TracChangeset for help on using the changeset viewer.