- Timestamp:
- May 3, 2017, 3:15:05 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- b13fc10
- Parents:
- c469f43
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/sched-int-multi.c
rc469f43 r1ed841f 2 2 #include <kernel> 3 3 #include <monitor> 4 #include <stdlib> 4 5 #include <thread> 5 6 … … 12 13 int counter; 13 14 state_t state; 15 16 unsigned short do_signal; 17 unsigned short do_wait2; 18 unsigned short do_wait1; 14 19 }; 15 20 … … 18 23 this->counter = 0; 19 24 this->state = BARGE; 25 26 this->do_signal = 6; 27 this->do_wait1 = 1; 28 this->do_wait2 = 3; 20 29 } 21 30 … … 33 42 c->counter++; 34 43 44 if( (c->counter % 1000) == 0 ) sout | c->counter | endl; 45 35 46 int action = c->counter % 10; 36 47 37 if( action == 1 || action == 3 ) { 38 if(c->state != BARGE) { 39 sout | "ERROR Mutual exclusion is inconsistent for wait" | endl; 40 abort(); 41 } 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); 42 52 53 // if(c->do_wait1 == c->do_wait2) sout | "Same" | endl; 54 } 55 56 if( action == c->do_wait1 || action == c->do_wait2 ) { 43 57 c->state = WAIT; 44 58 wait( &cond ); 45 59 46 60 if(c->state != SIGNAL) { 47 sout | "ERROR Barging detected" | endl;61 sout | "ERROR Barging detected" | c->counter | endl; 48 62 abort(); 49 63 } 50 64 } 51 else if( action == 6 ) { 52 if(c->state != BARGE) { 53 sout | "ERROR Mutual exclusion is inconsistent for signal" | endl; 54 abort(); 55 } 56 65 else if( action == c->do_signal ) { 57 66 c->state = SIGNAL; 58 67 … … 64 73 } 65 74 66 if( (c->counter % 1000) == 0 ) sout | c->counter | endl; 67 if( c->counter == 100_000 ) c->done = true; 75 if( c->counter >= 100_000 ) c->done = true; 68 76 return !c->done; 69 77 } … … 82 90 83 91 int main(int argc, char* argv[]) { 84 processor p[3]; 92 rand48seed(0); 93 processor p; 85 94 { 86 Threads t[ 20];95 Threads t[17]; 87 96 } 88 97 }
Note: See TracChangeset
for help on using the changeset viewer.