- Timestamp:
- Apr 1, 2022, 1:08:24 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- e71e94a
- Parents:
- 31ef267
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/io/comp_fair.cfa
r31ef267 r1417f6b 16 16 17 17 18 #include <concurrency/ locks.hfa>18 #include <concurrency/barrier.hfa> 19 19 #include <fstream.hfa> 20 20 #include <iofwd.hfa> … … 27 27 28 28 struct { 29 semaphore sem;29 barrier & bar; 30 30 int pipe[2]; 31 31 … … 59 59 yield(); 60 60 } 61 62 mutex(sout) sout | "Spinner done";63 61 } 64 62 … … 70 68 71 69 for(TIMES) { 72 yield( prng( this, 15 ) );73 74 70 io_future_t f; 75 71 if ( do_read ) { … … 80 76 } 81 77 82 P( globals.sem ); 78 block( globals.bar ); 79 80 yield( prng( this, 15 ) ); 83 81 84 82 unsigned i = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST ); … … 89 87 if(f.result < 0) 90 88 abort | "Read error" | -f.result | ":" | strerror(-f.result); 89 90 block( globals.bar ); 91 91 } 92 93 P( globals.sem );94 95 mutex(sout) sout | "Reader done";96 92 } 97 93 … … 102 98 void main(Writer & this) { 103 99 for(TIMES) { 104 yield( prng( this, 15 ) ); 105 106 V( globals.sem ); 100 block( globals.bar ); 107 101 108 102 sleep( 1`us ); … … 113 107 abort | "Write error" | errno | ":" | strerror(errno); 114 108 109 block( globals.bar ); 115 110 } 116 117 mutex(sout) sout | "Writer done";118 111 } 119 112 … … 126 119 yield(); 127 120 } 128 129 mutex(sout) sout | "Yielder done";130 121 } 131 122 132 123 int main() { 124 barrier bar = { 2 }; 125 &globals.bar = &bar; 133 126 int ret = pipe(globals.pipe); 134 127 if(ret != 0)
Note: See TracChangeset
for help on using the changeset viewer.