ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
deferred_resn
demangler
enum
forall-pointer-decay
jacob/cs343-translation
jenkins-sandbox
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
resolv-new
with_gc
Last change
on this file since 39c5ea3 was a933dcf4, checked in by Thierry Delisle <tdelisle@…>, 8 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 |
|
---|
6 | enum state_t { WAIT, SIGNAL, BARGE };
|
---|
7 |
|
---|
8 | monitor global_t {};
|
---|
9 |
|
---|
10 | monitor global_data_t {
|
---|
11 | bool done;
|
---|
12 | int counter;
|
---|
13 | state_t state;
|
---|
14 | };
|
---|
15 |
|
---|
16 | void ?{} ( global_data_t * this ) {
|
---|
17 | this->done = false;
|
---|
18 | this->counter = 0;
|
---|
19 | this->state = BARGE;
|
---|
20 | }
|
---|
21 |
|
---|
22 | void ^?{} ( global_data_t * this ) {}
|
---|
23 |
|
---|
24 | global_t globalA;
|
---|
25 | global_t globalB;
|
---|
26 | global_data_t globalC;
|
---|
27 |
|
---|
28 | condition cond;
|
---|
29 |
|
---|
30 | thread Threads {};
|
---|
31 |
|
---|
32 | bool 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 |
|
---|
71 | bool logicB( global_t * mutex a, global_t * mutex b ) {
|
---|
72 | return logicC(a, b, &globalC);
|
---|
73 | }
|
---|
74 |
|
---|
75 | bool logicA( global_t * mutex a ) {
|
---|
76 | return logicB(a, &globalB);
|
---|
77 | }
|
---|
78 |
|
---|
79 | void main( Threads* this ) {
|
---|
80 | while( logicA(&globalA) ) { yield(); };
|
---|
81 | }
|
---|
82 |
|
---|
83 | int 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.