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