#include #include // Test priority order of waitfor clauses. To get deterministic output for repeatable testing, preemption is disabled // and the threads defer to each other at certain points. Duration default_preemption() { return 0; } // disable preemption enum { Times = 50, Half = Times / 2 }; thread T {}; void f( T & mutex ) {} void g( T & mutex ) {} void main( T & t ) { sout | nlOff; for ( Times / Half ) { for ( Half ) { waitfor( f : t ) sout | "f"; or waitfor( g :t ) sout | "g"; // service f before g } // for for ( Half ) { waitfor( g : t ) sout | "g"; // service g before f or waitfor( f : t ) sout | "f"; } // for sout | "\n"; } // for } T t; // shared thread F{}; void main( F & ) { for ( Half ) f( t ); yield( 5 ); // let g get ahead for ( Half ) f( t ); } thread G{}; void main( G & ) { yield( 5 ); // let f get ahead for ( Half ) g( t ); for ( Half ) g( t ); } int main() { F f; G g; }