Changes in src/tests/sched-int-wait.c [19801aa:9737ffe]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/sched-int-wait.c
r19801aa r9737ffe 4 4 #include <stdlib> 5 5 #include <thread> 6 7 static const int N = 10_000;8 6 9 7 monitor global_t {}; … … 15 13 condition condAB, condAC, condBC, condABC; 16 14 17 thread Signaler {}; 15 thread Signaler { 16 int signals[4]; 17 }; 18 19 void ?{}( Signaler * this ){ 20 this->signals[0] = 0; 21 this->signals[1] = 0; 22 this->signals[2] = 0; 23 this->signals[3] = 0; 24 } 25 18 26 thread WaiterAB {}; 19 27 thread WaiterAC {}; … … 21 29 thread WaiterABC{}; 22 30 23 volatile int waiter_left;31 volatile bool done; 24 32 25 33 //---------------------------------------------------------------------------------------------------- … … 45 53 void main( Signaler* this ) { 46 54 47 while( waiter_left != 0 ) { 48 unsigned action = (unsigned)rand48() % 4; 55 while( true ) { 56 int action = (unsigned)rand48() % 4; 57 bool finished = true; 58 59 for(int i = 0; i < 4; i++) { 60 if( this->signals[action] < 10_000 ) { 61 finished = false; 62 break; 63 } 64 else { 65 action = (action + 1) % 4; 66 } 67 } 68 69 this->signals[action]++; 70 if( finished ) break; 71 72 //sout | action | this->signals[0] | this->signals[1] | this->signals[2] | this->signals[3] | endl; 73 49 74 switch( action ) { 50 75 case 0: … … 64 89 abort(); 65 90 } 66 yield();67 91 } 68 92 } … … 71 95 // Waiter ABC 72 96 void main( WaiterABC* this ) { 73 for( int i = 0; i < N; i++) {97 while( !done ) { 74 98 wait( &condABC, &globalA, &globalB, &globalC ); 75 99 } 76 77 __sync_fetch_and_sub_4( &waiter_left, 1);78 100 } 79 101 … … 81 103 // Waiter AB 82 104 void main( WaiterAB* this ) { 83 for( int i = 0; i < N; i++) {105 while( !done ) { 84 106 wait( &condAB , &globalA, &globalB ); 85 107 } 86 87 __sync_fetch_and_sub_4( &waiter_left, 1);88 108 } 89 109 … … 91 111 // Waiter AC 92 112 void main( WaiterAC* this ) { 93 for( int i = 0; i < N; i++) {113 while( !done ) { 94 114 wait( &condAC , &globalA, &globalC ); 95 115 } 96 97 __sync_fetch_and_sub_4( &waiter_left, 1);98 116 } 99 117 … … 101 119 // Waiter BC 102 120 void main( WaiterBC* this ) { 103 for( int i = 0; i < N; i++) {121 while( !done ) { 104 122 wait( &condBC , &globalB, &globalC ); 105 123 } 106 107 __sync_fetch_and_sub_4( &waiter_left, 1);108 124 } 109 125 … … 111 127 // Main 112 128 int main(int argc, char* argv[]) { 113 waiter_left = 4;129 done = false; 114 130 processor p; 115 131 { 116 Signaler e; 132 WaiterABC a; 133 WaiterAB b; 134 WaiterBC c; 135 WaiterAC d; 117 136 { 118 WaiterABC a; 119 WaiterAB b; 120 WaiterBC c; 121 WaiterAC d; 137 Signaler e; 122 138 } 139 done = true; 140 signal( &condABC, &globalA, &globalB, &globalC ); 141 signal( &condAB , &globalA, &globalB ); 142 signal( &condBC , &globalB, &globalC ); 143 signal( &condAC , &globalA, &globalC ); 123 144 } 124 145 }
Note:
See TracChangeset
for help on using the changeset viewer.