- Timestamp:
- May 4, 2017, 4:13:36 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:
- 9737ffe
- Parents:
- 4845ae2
- Location:
- src/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/.expect/concurrent/sched-int.txt
r4845ae2 r102a58b 1 Step 1 2 Step 2 3 Step 3 1 1000 2 2000 3 3000 4 4000 5 5000 6 6000 7 7000 8 8000 9 9000 10 10000 11 11000 12 12000 13 13000 14 14000 15 15000 16 16000 17 17000 18 18000 19 19000 20 20000 21 21000 22 22000 23 23000 24 24000 25 25000 26 26000 27 27000 28 28000 29 29000 30 30000 31 31000 32 32000 33 33000 34 34000 35 35000 36 36000 37 37000 38 38000 39 39000 40 40000 41 41000 42 42000 43 43000 44 44000 45 45000 46 46000 47 47000 48 48000 49 49000 50 50000 51 51000 52 52000 53 53000 54 54000 55 55000 56 56000 57 57000 58 58000 59 59000 60 60000 61 61000 62 62000 63 63000 64 64000 65 65000 66 66000 67 67000 68 68000 69 69000 70 70000 71 71000 72 72000 73 73000 74 74000 75 75000 76 76000 77 77000 78 78000 79 79000 80 80000 81 81000 82 82000 83 83000 84 84000 85 85000 86 86000 87 87000 88 88000 89 89000 90 90000 91 91000 92 92000 93 93000 94 94000 95 95000 96 96000 97 97000 98 98000 99 99000 100 100000 101 All waiter done -
src/tests/sched-int.c
r4845ae2 r102a58b 4 4 #include <thread> 5 5 6 monitor global_t { 7 int value; 8 }; 6 #define N 100_000 9 7 10 global_t global; 8 enum state_t { WAIT, SIGNAL, BARGE }; 9 10 monitor global_t {}; 11 global_t mut; 12 13 monitor global_data_t; 14 void ?{}( global_data_t * this ); 15 void ^?{} ( global_data_t * this ); 16 17 monitor global_data_t { 18 int counter; 19 state_t state; 20 } data; 11 21 12 22 condition cond; 13 23 14 thread Signalee {}; 15 thread Signaler {}; 24 volatile bool all_done; 16 25 17 void step1( global_t * mutex this ) { 18 sout | "Step 1" | endl; 19 this->value = 1; 20 wait( &cond ); 26 void ?{}( global_data_t * this ) { 27 this->counter == 0; 28 this->state = BARGE; 21 29 } 22 30 23 void step2( global_t * mutex this ) { 24 if( this->value != 1) abort(); 31 void ^?{} ( global_data_t * this ) {} 25 32 26 sout | "Step 2" | endl; 27 this->value = 2; 28 signal( &cond ); 33 //------------------------------------------------------------------------------ 34 // Barging logic 35 void barge( global_data_t * mutex d ) { 36 d->state = BARGE; 29 37 } 30 38 31 void step3( global_t * mutex this ) { 32 if( this->value != 2) abort(); 39 thread Barger {}; 33 40 34 sout | "Step 3" | endl; 35 this->value = 3; 36 signal( &cond ); 41 void main( Barger * this ) { 42 while( !all_done ) { 43 barge( &data ); 44 yield(); 45 } 37 46 } 38 47 39 void main( Signalee* this ) { 40 step1( &global ); 41 step3( &global ); 48 //------------------------------------------------------------------------------ 49 // Waiting logic 50 bool wait( global_t * mutex m, global_data_t * mutex d ) { 51 wait( &cond ); 52 if( d->state != SIGNAL ) { 53 sout | "ERROR barging!" | endl; 54 } 55 56 d->counter++; 57 58 if( (d->counter % 1000) == 0 ) sout | d->counter | endl; 59 60 return d->counter < N; 42 61 } 43 62 44 void main( Signaler* this ) { 45 for(int i = 0; i < 10_000; i++) { 46 asm volatile ("" : : : "memory"); 63 thread Waiter {}; 64 65 void main( Waiter * this ) { 66 while( wait( &mut, &data ) ) { yield(); } 67 } 68 69 70 //------------------------------------------------------------------------------ 71 // Signalling logic 72 void signal( condition * cond, global_t * mutex a, global_data_t * mutex b ) { 73 b->state = SIGNAL; 74 signal( cond ); 75 } 76 77 void logic( global_t * mutex a ) { 78 signal( &cond, a, &data ); 79 80 int pauses = (unsigned)rand48() % 10; 81 for(int i = 0; i < pauses; i++) { 82 yield(); 47 83 } 48 84 49 step2( &global ); 85 //This is technically a mutual exclusion violation but the mutex monitor protects us 86 bool running = data.counter < N && data.counter > 0; 87 if( data.state != SIGNAL && running ) { 88 sout | "ERROR Eager signal" | data.state | endl; 89 } 50 90 } 51 91 92 thread Signaller {}; 93 94 void main( Signaller * this ) { 95 while( !all_done ) { 96 logic( &mut ); 97 yield(); 98 } 99 } 100 101 //------------------------------------------------------------------------------ 102 // Main loop 52 103 int main(int argc, char* argv[]) { 53 a ssert( global.__mon.entry_queue.tail != NULL );104 all_done = false; 54 105 processor p; 55 106 { 56 Signalee a; 57 Signaler b; 58 } 59 if( global.value != 3) abort(); 107 Signaller s; 108 Barger b[17]; 109 { 110 Waiter w[4]; 111 } 112 sout | "All waiter done" | endl; 113 all_done = true; 114 } 60 115 }
Note: See TracChangeset
for help on using the changeset viewer.