Last change
on this file since f6f7b52 was
f6f7b52,
checked in by kyoung <lseo@…>, 4 days ago
|
fixed a parser bug to generate correct ast for waitfor.
added a test program to check if we are respecting waitfor lexical priority.
|
-
Property mode set to
100644
|
File size:
1013 bytes
|
Line | |
---|
1 | #include <thread.hfa> |
---|
2 | #include <fstream.hfa> |
---|
3 | |
---|
4 | // Test priority order of waitfor clauses. To get deterministic output for repeatable testing, preemption is disabled |
---|
5 | // and the threads defer to each other at certain points. |
---|
6 | |
---|
7 | Duration default_preemption() { return 0; } // disable preemption |
---|
8 | |
---|
9 | enum { Times = 50, Half = Times / 2 }; |
---|
10 | |
---|
11 | thread T {}; |
---|
12 | void f( T & mutex ) {} |
---|
13 | void g( T & mutex ) {} |
---|
14 | void main( T & t ) { |
---|
15 | sout | nlOff; |
---|
16 | for ( Times / Half ) { |
---|
17 | for ( Half ) { |
---|
18 | waitfor( f : t ) sout | "f"; |
---|
19 | or waitfor( g :t ) sout | "g"; // service f before g |
---|
20 | } // for |
---|
21 | for ( Half ) { |
---|
22 | waitfor( g : t ) sout | "g"; // service g before f |
---|
23 | or waitfor( f : t ) sout | "f"; |
---|
24 | } // for |
---|
25 | sout | "\n"; |
---|
26 | } // for |
---|
27 | } |
---|
28 | |
---|
29 | T t; // shared |
---|
30 | |
---|
31 | thread F{}; |
---|
32 | void main( F & ) { |
---|
33 | for ( Half ) f( t ); |
---|
34 | yield( 5 ); // let g get ahead |
---|
35 | for ( Half ) f( t ); |
---|
36 | } |
---|
37 | thread G{}; |
---|
38 | void main( G & ) { |
---|
39 | yield( 5 ); // let f get ahead |
---|
40 | for ( Half ) g( t ); |
---|
41 | for ( Half ) g( t ); |
---|
42 | } |
---|
43 | |
---|
44 | int main() { |
---|
45 | F f; |
---|
46 | G g; |
---|
47 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.