source: tests/concurrent/once.cfa @ d2ad151

ADTast-experimental
Last change on this file since d2ad151 was d2ad151, checked in by Peter A. Buhr <pabuhr@…>, 18 months ago

major update of PRNG

  • Property mode set to 100644
File size: 658 bytes
Line 
1#include <barrier.hfa>
2#include <fstream.hfa>
3#include <kernel.hfa>
4#include <once.hfa>
5#include <thread.hfa>
6
7once_flag global;
8
9volatile int check;
10
11void reset() {
12        (global){};
13        check = 0;
14}
15
16void 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
23barrier barr = { 11 };
24
25thread Tester {};
26
27void main( Tester & this ) {
28        for(500) {
29                block( barr, reset );
30
31                // sometime yields
32                yield( (unsigned)prng(this, 3) );
33        }
34}
35
36int 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.