source: tests/concurrency/waitfor/lexical_priority.cfa@ 6cb3e5d

Last change on this file since 6cb3e5d was 9c65169, checked in by Peter A. Buhr <pabuhr@…>, 8 months ago

reduce yields in test but still get deterministic results

  • Property mode set to 100644
File size: 969 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
7Duration default_preemption() { return 0; } // disable preemption
8
9enum { Times = 50, Half = Times / 2 };
10
11thread T {};
12void f( T & mutex ) {}
13void g( T & mutex ) {}
14void 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
29T t; // shared
30
31thread F{};
32void main( F & ) {
33 for ( Half ) f( t );
34 for ( Half ) f( t );
35}
36
37thread G{};
38void main( G & ) {
39 for ( Half ) g( t );
40 for ( Half ) g( t );
41}
42
43int main() {
44 F f;
45 yield(); // let f get ahead
46 G g;
47}
Note: See TracBrowser for help on using the repository browser.