source:
tests/concurrent/once.cfa@
19a8c40
| Last change on this file since 19a8c40 was e8b8e65, checked in by , 3 years ago | |
|---|---|
|
|
| File size: 645 bytes | |
| Rev | Line | |
|---|---|---|
| [e8b8e65] | 1 | #include <barrier.hfa> |
| 2 | #include <fstream.hfa> | |
| 3 | #include <kernel.hfa> | |
| 4 | #include <once.hfa> | |
| 5 | #include <thread.hfa> | |
| 6 | ||
| 7 | once_flag global; | |
| 8 | ||
| 9 | volatile int check; | |
| 10 | ||
| 11 | void reset() { | |
| 12 | (global){}; | |
| 13 | check = 0; | |
| 14 | } | |
| 15 | ||
| 16 | void must_once(void) { | |
| 17 | int prev = __atomic_fetch_add( &check, 1, __ATOMIC_SEQ_CST ); | |
| 18 | if(prev != 0) { | |
| 19 | abort | "'must_once' appears to have been called more than once, check was" | prev; | |
| 20 | } | |
| 21 | } | |
| 22 | ||
| 23 | barrier barr = { 11 }; | |
| 24 | ||
| 25 | thread Tester {}; | |
| 26 | ||
| 27 | void main( Tester & this ) { | |
| 28 | for(500) { | |
| 29 | block( barr, reset ); | |
| 30 | ||
| 31 | // sometime yields | |
| 32 | yield(prng(this, 3)); | |
| 33 | } | |
| 34 | } | |
| 35 | ||
| 36 | int main() { | |
| 37 | processor p[2]; | |
| 38 | ||
| 39 | sout | "starting"; | |
| 40 | { | |
| 41 | Tester testers[11]; | |
| 42 | } | |
| 43 | sout | "done"; | |
| 44 | } |
Note:
See TracBrowser
for help on using the repository browser.