Ignore:
Timestamp:
Sep 21, 2022, 11:02:15 AM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
95dab9e
Parents:
428adbc (diff), 0bd46fd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into pthread-emulation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/io/comp_fair.cfa

    r428adbc r7f6a7c9  
    2727
    2828struct {
    29       barrier & bar;
    30       int pipe[2];
     29        barrier & bar;
     30        int pipe[2];
    3131
    3232} globals;
     
    6565thread Reader {};
    6666void main(Reader & this) {
    67       bool do_read = has_user_level_blocking( (fptr_t)async_read );
     67        char thrash[1];
     68        bool do_read = has_user_level_blocking( (fptr_t)async_read );
    6869
    69       for(TIMES) {
    70             io_future_t f;
    71             if ( do_read ) {
    72                   char thrash[1];
    73                   async_read(f, globals.pipe[0], thrash, 1, 0);
    74             } else {
    75                   fulfil(f, 0); // If we don't have user-level blocking just play along
    76             }
     70        for(TIMES) {
     71                io_future_t f;
     72                if ( do_read ) {
     73                        async_read(f, globals.pipe[0], thrash, 1, 0);
     74                } else {
     75                        fulfil(f, 0); // If we don't have user-level blocking just play along
     76                }
    7777
    78             block( globals.bar );
     78                block( globals.bar );
    7979
    8080                yield( prng( this, 15 ) );
    8181
    82             unsigned i = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
     82                unsigned i = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
    8383                if(0 == (i % 100)) sout | i;
    8484
    85             wait( f );
     85                wait( f );
    8686
    87             if(f.result < 0)
    88                   abort | "Read error" | -f.result | ":" | strerror(-f.result);
     87                if(f.result < 0)
     88                        abort | "Read error" | -f.result | ":" | strerror(-f.result);
    8989
    90             block( globals.bar );
    91       }
     90                block( globals.bar );
     91        }
    9292}
    9393
     
    9797thread Writer {};
    9898void main(Writer & this) {
    99       for(TIMES) {
    100             block( globals.bar );
     99        for(TIMES) {
     100                block( globals.bar );
    101101
    102             sleep( 1`us );
     102                sleep( 1`us );
    103103
    104             char buf[1] = { '+' };
    105             int ret = write( globals.pipe[1], buf, 1 );
    106             if(ret < 0)
    107                   abort | "Write error" | errno | ":" | strerror(errno);
     104                char buf[1] = { '+' };
     105                int ret = write( globals.pipe[1], buf, 1 );
     106                if(ret < 0)
     107                        abort | "Write error" | errno | ":" | strerror(errno);
    108108
    109             block( globals.bar );
    110       }
     109                block( globals.bar );
     110        }
    111111}
    112112
     
    122122
    123123int main() {
    124       barrier bar = { 2 };
    125       &globals.bar = &bar;
    126       int ret = pipe(globals.pipe);
    127       if(ret != 0)
    128             abort | "Pipe error" | errno | ":" | strerror(errno);
     124        barrier bar = { 2 };
     125        &globals.bar = &bar;
     126        int ret = pipe(globals.pipe);
     127        if(ret != 0)
     128                abort | "Pipe error" | errno | ":" | strerror(errno);
    129129
    130130        processor p;
     
    134134                Spinner s;
    135135                Reader ior;
    136             Writer iow;
     136                Writer iow;
    137137        }
    138138        sout | "done";
Note: See TracChangeset for help on using the changeset viewer.