| Last change
 on this file since a55ebcc was             c26bea2a, checked in by Peter A. Buhr <pabuhr@…>, 2 years ago | 
        
          | 
first attempt at renaming directory tests/concurrent to tests/concurrency to harmonize with other concurrency directory names
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            648 bytes | 
      
      
| Line |  | 
|---|
| 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.