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