Last change
on this file since b5f1e850 was
c26bea2a,
checked in by Peter A. Buhr <pabuhr@…>, 18 months 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:
848 bytes
|
Line | |
---|
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.