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