ADT
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since 6d8e1ab was             7bd23ce, checked in by Thierry Delisle <tdelisle@…>, 4 years ago | 
        
          | 
Tentative fix to sleep.cfa make it more robust
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            683 bytes | 
      
      
| Rev | Line |  | 
|---|
| [c457dc41] | 1 | #include <fstream.hfa> | 
|---|
|  | 2 | #include <thread.hfa> | 
|---|
|  | 3 | #include <time.hfa> | 
|---|
|  | 4 |  | 
|---|
|  | 5 | Duration default_preemption() { | 
|---|
|  | 6 | return 0; | 
|---|
|  | 7 | } | 
|---|
|  | 8 |  | 
|---|
| [7bd23ce] | 9 | volatile int counter = 0; | 
|---|
|  | 10 |  | 
|---|
| [c457dc41] | 11 | thread fast_sleeper {}; | 
|---|
|  | 12 | void main(fast_sleeper &) { | 
|---|
|  | 13 | Duration wait = 47`ms; | 
|---|
|  | 14 | for(i; 20) { | 
|---|
|  | 15 | sleep(wait); | 
|---|
| [7bd23ce] | 16 | __atomic_fetch_add( &counter, 1, __ATOMIC_RELAXED ); | 
|---|
| [c457dc41] | 17 | } | 
|---|
|  | 18 | } | 
|---|
|  | 19 |  | 
|---|
|  | 20 | thread slow_sleeper {}; | 
|---|
|  | 21 | void main(slow_sleeper &) { | 
|---|
|  | 22 | Duration wait = 277`ms; | 
|---|
|  | 23 | for(i; 4) { | 
|---|
|  | 24 | sleep(wait); | 
|---|
| [7bd23ce] | 25 | int val = __atomic_add_fetch( &counter, -5, __ATOMIC_RELAXED ); | 
|---|
|  | 26 | if(val < -9) abort | "Value reached negative value:" | val; | 
|---|
| [c457dc41] | 27 | } | 
|---|
|  | 28 | } | 
|---|
|  | 29 |  | 
|---|
|  | 30 | int main() { | 
|---|
|  | 31 | sout | acquire | "start"; | 
|---|
|  | 32 | { | 
|---|
|  | 33 | slow_sleeper slow; | 
|---|
|  | 34 | yield(); | 
|---|
|  | 35 | fast_sleeper fast; | 
|---|
|  | 36 | yield(); | 
|---|
|  | 37 | } | 
|---|
|  | 38 | sout | acquire | "done"; | 
|---|
|  | 39 | } | 
|---|
|  | 40 |  | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.