source: src/tests/sched-int-multi2.c @ 2e5ad9f

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 2e5ad9f was 2e5ad9f, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Added more rigorous multi monitor internal scheduling

  • Property mode set to 100644
File size: 2.9 KB
Line 
1#include <fstream>
2#include <kernel>
3#include <monitor>
4#include <thread>
5
6monitor global_t {};
7
8global_t globalA;
9global_t globalB;
10global_t globalC;
11
12condition condAB, condAC, condBC, condABC;
13
14thread Signaler {};
15thread WaiterAB {};
16thread WaiterAC {};
17thread WaiterBC {};
18thread WaiterABC{};
19
20int state;
21
22/*
23multi phase
24*/
25
26//----------------------------------------------------------------------------------------------------
27// Tools
28void signal( condition * cond, global_t * mutex a, global_t * mutex b ) {
29        signal( cond );
30}
31
32void signal( condition * cond, global_t * mutex a, global_t * mutex b, global_t * mutex c ) {
33        signal( cond );
34}
35
36void wait( condition * cond, global_t * mutex a, global_t * mutex b ) {
37        state++;
38        sout | "Waiting" | state | endl;
39        wait( cond );
40        sout | "Waking" | state | endl;
41        state--;
42}
43
44void wait( condition * cond, global_t * mutex a, global_t * mutex b, global_t * mutex c ) {
45        state++;
46        sout | "Waiting" | state | endl;
47        wait( cond );
48        sout | "Waking" | state | endl;
49        state--;
50}
51
52//----------------------------------------------------------------------------------------------------
53// Signaler
54// signals respectively AB, AC, BC, ABC
55void signalerABC( global_t * mutex a, global_t * mutex b, global_t * mutex c ) {
56        sout | "Signaling ABC" | endl;
57        signal( &condABC, a, b, c );
58        sout | "Signaling AB" | endl;
59        signal( &condAB , a, b );
60        sout | "Signaling BC" | endl;
61        signal( &condBC , b, c );
62        sout | "Signaling AC" | endl;
63        signal( &condAC , a, c );
64}
65
66void signalerAB( global_t * mutex a, global_t * mutex b, global_t * c ) {
67        signalerABC(a, b, c);
68}
69
70void signalerA( global_t * mutex a, global_t * b, global_t * c ) {
71        signalerAB (a, b, c);
72}
73
74void main( Signaler* this ) {
75        while( state != 4 ) { yield(); }
76        signalerA( &globalA, &globalB, &globalC );
77}
78
79//----------------------------------------------------------------------------------------------------
80// Waiter ABC
81void main( WaiterABC* this ) {
82        while( state != 0 ) { yield(); }
83        wait( &condABC, &globalA, &globalB, &globalC );
84}
85
86//----------------------------------------------------------------------------------------------------
87// Waiter AB
88void main( WaiterAB* this ) {
89        while( state != 1 ) { yield(); }
90        wait( &condAB , &globalA, &globalB );
91}
92
93//----------------------------------------------------------------------------------------------------
94// Waiter AC
95void main( WaiterAC* this ) {
96        while( state != 2 ) { yield(); }
97        wait( &condAC , &globalA, &globalC );
98}
99
100//----------------------------------------------------------------------------------------------------
101// Waiter BC
102void main( WaiterBC* this ) {
103        while( state != 3 ) { yield(); }
104        wait( &condBC , &globalB, &globalC );
105}
106
107//----------------------------------------------------------------------------------------------------
108// Main
109int main(int argc, char* argv[]) {
110        state = 0;
111        processor p;
112        {
113                WaiterABC a;
114                WaiterAB  b;
115                WaiterBC  c;
116                WaiterAC  d;
117                Signaler  e;
118        }
119}
Note: See TracBrowser for help on using the repository browser.