ADT
        ast-experimental
        enum
        forall-pointer-decay
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since a2a4566 was             0dbecad, checked in by Thierry Delisle <tdelisle@…>, 5 years ago | 
        
          | 
Added tests for join thread
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            848 bytes | 
      
      
| Rev | Line |  | 
|---|
| [0dbecad] | 1 | #include <fstream.hfa> | 
|---|
|  | 2 | #include <thread.hfa> | 
|---|
|  | 3 |  | 
|---|
|  | 4 | thread Worker { volatile int result; }; | 
|---|
|  | 5 |  | 
|---|
|  | 6 | void main(Worker & this) { | 
|---|
|  | 7 | this.result = -10; | 
|---|
|  | 8 | for(50) { | 
|---|
|  | 9 | yield(); | 
|---|
|  | 10 | } | 
|---|
|  | 11 | this.result = 42; | 
|---|
|  | 12 | } | 
|---|
|  | 13 |  | 
|---|
|  | 14 | thread OtherWorker { volatile int result; }; | 
|---|
|  | 15 |  | 
|---|
|  | 16 | void main(OtherWorker & this) { | 
|---|
|  | 17 | this.result = -10; | 
|---|
|  | 18 | LOOP: for() { | 
|---|
|  | 19 | waitfor( ^?{} : this) { | 
|---|
|  | 20 | break LOOP; | 
|---|
|  | 21 | } | 
|---|
|  | 22 | or else { | 
|---|
|  | 23 | yield(); | 
|---|
|  | 24 | } | 
|---|
|  | 25 | } | 
|---|
|  | 26 | this.result = 27; | 
|---|
|  | 27 | } | 
|---|
|  | 28 |  | 
|---|
|  | 29 |  | 
|---|
|  | 30 | int main(int argc, char* argv[]) { | 
|---|
|  | 31 | { | 
|---|
|  | 32 | Worker workers[17]; | 
|---|
|  | 33 | for(i; 17) { | 
|---|
|  | 34 | int res = join( workers[i] ).result; | 
|---|
|  | 35 | if( res != 42 ) { | 
|---|
|  | 36 | sout | "Worker" | i | "got incorrect result:" | res; | 
|---|
|  | 37 | } | 
|---|
|  | 38 | } | 
|---|
|  | 39 | } | 
|---|
|  | 40 | sout | "All workers got 42"; | 
|---|
|  | 41 |  | 
|---|
|  | 42 | { | 
|---|
|  | 43 | OtherWorker workers[17]; | 
|---|
|  | 44 | for(i; 17) { | 
|---|
|  | 45 | int res = join( workers[i] ).result; | 
|---|
|  | 46 | if( res != 27 ) { | 
|---|
|  | 47 | sout | "Other Worker" | i | "got incorrect result:" | res; | 
|---|
|  | 48 | } | 
|---|
|  | 49 | } | 
|---|
|  | 50 | } | 
|---|
|  | 51 | sout | "All other workers got 27"; | 
|---|
|  | 52 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.