source: src/tests/sched-int-wait.c @ 5c69a1e

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 5c69a1e was 43123e0, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Added print to sched-int-wait to tests test regen from jenkins

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