source: src/tests/sched-int-multi.c @ 39c5ea3

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 39c5ea3 was a933dcf4, checked in by Thierry Delisle <tdelisle@…>, 7 years ago
  • updated internal scheduler test for multi monitors
  • fixed branding for monitors
  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include <fstream>
2#include <kernel>
3#include <monitor>
4#include <thread>
5
6enum state_t { WAIT, SIGNAL, BARGE };
7
8monitor global_t {};
9
10monitor global_data_t {
11        bool done;
12        int counter;
13        state_t state;
14};
15
16void ?{} ( global_data_t * this ) {
17        this->done = false;
18        this->counter = 0;
19        this->state = BARGE;
20}
21
22void ^?{} ( global_data_t * this ) {}
23
24global_t globalA;
25global_t globalB;
26global_data_t globalC;
27
28condition cond;
29
30thread Threads {};
31
32bool logicC( global_t * mutex a, global_t * mutex b, global_data_t * mutex c ) {
33        c->counter++;
34
35        int action = c->counter % 10;
36
37        if( action == 1 || action == 3 ) {
38                if(c->state != BARGE) {
39                        sout | "ERROR Mutual exclusion is inconsistent for wait" | endl;
40                        abort();
41                }
42
43                c->state = WAIT;
44                wait( &cond );
45
46                if(c->state != SIGNAL) {
47                        sout | "ERROR Barging detected" | endl;
48                        abort();
49                }
50        }
51        else if( action == 6 ) {
52                if(c->state != BARGE) {
53                        sout | "ERROR Mutual exclusion is inconsistent for signal" | endl;
54                        abort();
55                }
56
57                c->state = SIGNAL;
58
59                signal( &cond );
60                signal( &cond );
61        }
62        else {
63                c->state = BARGE;
64        }
65
66        if( (c->counter % 1000) == 0 ) sout | c->counter | endl;
67        if( c->counter == 100_000 ) c->done = true;
68        return !c->done;
69}
70
71bool logicB( global_t * mutex a, global_t * mutex b ) {
72        return logicC(a, b, &globalC);
73}
74
75bool logicA( global_t * mutex a ) {
76        return logicB(a, &globalB);
77}
78
79void main( Threads* this ) {
80        while( logicA(&globalA) ) { yield(); };
81}
82
83int main(int argc, char* argv[]) {
84        processor p[3];
85        {
86                Threads t[20];
87        }
88}
Note: See TracBrowser for help on using the repository browser.