- Timestamp:
- Aug 11, 2017, 10:10:26 AM (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:
- fd344aa
- Parents:
- 8499c707
- Location:
- src/tests
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/coroutine.c
r8499c707 r83a071f9 25 25 } 26 26 27 void main( Fibonacci *this ) {27 void main( Fibonacci & this ) { 28 28 int fn1, fn2; // retained between resumes 29 this ->fn = 0; // case 030 fn1 = this ->fn;29 this.fn = 0; // case 0 30 fn1 = this.fn; 31 31 suspend(); // return to last resume 32 32 33 this ->fn = 1; // case 133 this.fn = 1; // case 1 34 34 fn2 = fn1; 35 fn1 = this ->fn;35 fn1 = this.fn; 36 36 suspend(); // return to last resume 37 37 38 38 for ( ;; ) { // general case 39 this ->fn = fn1 + fn2;39 this.fn = fn1 + fn2; 40 40 fn2 = fn1; 41 fn1 = this ->fn;41 fn1 = this.fn; 42 42 suspend(); // return to last resume 43 43 } // for 44 44 } 45 45 46 int next( Fibonacci *this ) {46 int next( Fibonacci & this ) { 47 47 resume( this ); // transfer to last suspend 48 return this ->fn;48 return this.fn; 49 49 } 50 50 … … 52 52 Fibonacci f1, f2; 53 53 for ( int i = 1; i <= 10; i += 1 ) { 54 sout | next( &f1 ) | ' ' | next( &f2 ) | endl;54 sout | next( f1 ) | ' ' | next( f2 ) | endl; 55 55 } // for 56 56 } -
src/tests/monitor.c
r8499c707 r83a071f9 14 14 static global_t global; 15 15 16 void increment3( global_t *mutex this ) {17 this ->value += 1;16 void increment3( global_t & mutex this ) { 17 this.value += 1; 18 18 } 19 19 20 void increment2( global_t *mutex this ) {20 void increment2( global_t & mutex this ) { 21 21 increment3( this ); 22 22 } 23 23 24 void increment( global_t *mutex this ) {24 void increment( global_t & mutex this ) { 25 25 increment2( this ); 26 26 } … … 28 28 thread MyThread {}; 29 29 30 void main( MyThread *this ) {30 void main( MyThread & this ) { 31 31 for(int i = 0; i < 1_000_000; i++) { 32 increment( &global );32 increment( global ); 33 33 } 34 34 } -
src/tests/multi-monitor.c
r8499c707 r83a071f9 10 10 static monitor_t m1, m2, m3; 11 11 12 void increment( monitor_t * mutex p1, monitor_t * mutex p2, int *value ) {13 *value += 1;12 void increment( monitor_t & mutex p1, monitor_t & mutex p2, int & value ) { 13 value += 1; 14 14 } 15 15 16 struct MyThread { 17 thread_desc __thrd; 16 thread MyThread { 18 17 int target; 19 18 }; 20 21 DECL_THREAD(MyThread);22 19 23 20 void ?{}( MyThread & this, int target ) { … … 27 24 void ^?{}( MyThread & mutex this ) {} 28 25 29 void main( MyThread *this ) {26 void main( MyThread & this ) { 30 27 for(int i = 0; i < 1000000; i++) { 31 choose(this ->target) {32 case 0: increment( &m1, &m2, &global12 );33 case 1: increment( &m2, &m3, &global23 );34 case 2: increment( &m1, &m3, &global13 );28 choose(this.target) { 29 case 0: increment( m1, m2, global12 ); 30 case 1: increment( m2, m3, global23 ); 31 case 2: increment( m1, m3, global13 ); 35 32 } 36 33 } 34 } 35 36 forall(dtype T | sized(T) | { void ^?{}(T & mutex); }) 37 void delete_mutex(T * x) { 38 ^(*x){}; 39 free(x); 37 40 } 38 41 … … 40 43 processor p; 41 44 { 42 scoped(MyThread)* f[6];45 MyThread * f[6]; 43 46 for(int i = 0; i < 6; i++) { 44 f[i] = (*(scoped(MyThread) *)malloc()){ i % 3 };47 f[i] = new(i % 3); 45 48 } 46 49 47 50 for(int i = 0; i < 6; i++) { 48 delete ( f[i] );51 delete_mutex( f[i] ); 49 52 } 50 53 } -
src/tests/preempt.c
r8499c707 r83a071f9 20 20 } 21 21 22 void main(worker_t *this) {22 void main(worker_t & this) { 23 23 while(counter < 1000) { 24 if( (counter % 7) == this ->value ) {24 if( (counter % 7) == this.value ) { 25 25 int next = __atomic_add_fetch_4(&counter, 1, __ATOMIC_SEQ_CST); 26 26 if( (next % 100) == 0 ) printf("%d\n", next); -
src/tests/sched-int-barge.c
r8499c707 r83a071f9 39 39 thread Threads {}; 40 40 41 bool logicC( global_t * mutex a, global_t * mutex b, global_data_t *mutex c ) {42 c ->counter++;41 bool logicC( global_t & mutex a, global_t & mutex b, global_data_t & mutex c ) { 42 c.counter++; 43 43 44 if( (c ->counter % 1000) == 0 ) sout | c->counter | endl;44 if( (c.counter % 1000) == 0 ) sout | c.counter | endl; 45 45 46 int action = c ->counter % 10;46 int action = c.counter % 10; 47 47 48 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);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); 52 52 53 // if(c ->do_wait1 == c->do_wait2) sout | "Same" | endl;53 // if(c.do_wait1 == c.do_wait2) sout | "Same" | endl; 54 54 } 55 55 56 if( action == c ->do_wait1 || action == c->do_wait2 ) {57 c ->state = WAIT;56 if( action == c.do_wait1 || action == c.do_wait2 ) { 57 c.state = WAIT; 58 58 wait( &cond ); 59 59 60 if(c ->state != SIGNAL) {61 sout | "ERROR Barging detected" | c ->counter | endl;60 if(c.state != SIGNAL) { 61 sout | "ERROR Barging detected" | c.counter | endl; 62 62 abort(); 63 63 } 64 64 } 65 else if( action == c ->do_signal ) {66 c ->state = SIGNAL;65 else if( action == c.do_signal ) { 66 c.state = SIGNAL; 67 67 68 68 signal( &cond ); … … 70 70 } 71 71 else { 72 c ->state = BARGE;72 c.state = BARGE; 73 73 } 74 74 75 if( c ->counter >= 100_000 ) c->done = true;76 return !c ->done;75 if( c.counter >= 100_000 ) c.done = true; 76 return !c.done; 77 77 } 78 78 79 bool logicB( global_t * mutex a, global_t *mutex b ) {80 return logicC(a, b, &globalC);79 bool logicB( global_t & mutex a, global_t & mutex b ) { 80 return logicC(a, b, globalC); 81 81 } 82 82 83 bool logicA( global_t *mutex a ) {84 return logicB(a, &globalB);83 bool logicA( global_t & mutex a ) { 84 return logicB(a, globalB); 85 85 } 86 86 87 void main( Threads *this ) {88 while( logicA( &globalA) ) { yield(); };87 void main( Threads & this ) { 88 while( logicA(globalA) ) { yield(); }; 89 89 } 90 90 -
src/tests/sched-int-block.c
r8499c707 r83a071f9 30 30 31 31 //------------------------------------------------------------------------------ 32 void wait_op( global_data_t * mutex a, global_data_t *mutex b, unsigned i ) {32 void wait_op( global_data_t & mutex a, global_data_t & mutex b, unsigned i ) { 33 33 wait( &cond, (uintptr_t)this_thread ); 34 34 35 35 yield( ((unsigned)rand48()) % 10 ); 36 36 37 if(a ->last_thread != a->last_signaller || b->last_thread != b->last_signaller ) {38 sout | "ERROR Barging detected, expected" | a ->last_signaller | b->last_signaller | "got" | a->last_thread | b->last_thread | endl;37 if(a.last_thread != a.last_signaller || b.last_thread != b.last_signaller ) { 38 sout | "ERROR Barging detected, expected" | a.last_signaller | b.last_signaller | "got" | a.last_thread | b.last_thread | endl; 39 39 abort(); 40 40 } 41 41 42 a ->last_thread = b->last_thread = this_thread;42 a.last_thread = b.last_thread = this_thread; 43 43 44 44 yield( ((unsigned)rand48()) % 10 ); … … 46 46 47 47 thread Waiter {}; 48 void main( Waiter *this ) {48 void main( Waiter & this ) { 49 49 for( int i = 0; i < N; i++ ) { 50 wait_op( &globalA, &globalB, i );50 wait_op( globalA, globalB, i ); 51 51 } 52 52 } 53 53 54 54 //------------------------------------------------------------------------------ 55 void signal_op( global_data_t * mutex a, global_data_t *mutex b ) {55 void signal_op( global_data_t & mutex a, global_data_t & mutex b ) { 56 56 yield( ((unsigned)rand48()) % 10 ); 57 57 58 a->last_thread = b->last_thread = a->last_signaller = b->last_signaller= this_thread;58 [a.last_thread, b.last_thread, a.last_signaller, b.last_signaller] = this_thread; 59 59 60 60 if( !is_empty( &cond ) ) { … … 69 69 yield( ((unsigned)rand48()) % 10 ); 70 70 71 if(a ->last_thread != next || b->last_thread != next) {72 sout | "ERROR Barging detected, expected" | next | "got" | a ->last_thread | b->last_thread | endl;71 if(a.last_thread != next || b.last_thread != next) { 72 sout | "ERROR Barging detected, expected" | next | "got" | a.last_thread | b.last_thread | endl; 73 73 abort(); 74 74 } … … 78 78 79 79 thread Signaller {}; 80 void main( Signaller *this ) {80 void main( Signaller & this ) { 81 81 while( !done ) { 82 signal_op( &globalA, &globalB );82 signal_op( globalA, globalB ); 83 83 } 84 84 } 85 85 86 86 //------------------------------------------------------------------------------ 87 void barge_op( global_data_t *mutex a ) {88 a ->last_thread = this_thread;87 void barge_op( global_data_t & mutex a ) { 88 a.last_thread = this_thread; 89 89 } 90 90 91 91 thread Barger {}; 92 void main( Barger *this ) {92 void main( Barger & this ) { 93 93 for( unsigned i = 0; !done; i++ ) { 94 94 //Choose some monitor to barge into with some irregular pattern 95 95 bool choose_a = (i % 13) > (i % 17); 96 barge_op( choose_a ? &globalA : &globalB ); 96 if ( choose_a ) barge_op( globalA ); 97 else barge_op( globalB ); 97 98 } 98 99 } -
src/tests/sched-int-disjoint.c
r8499c707 r83a071f9 35 35 //------------------------------------------------------------------------------ 36 36 // Barging logic 37 void barge( global_data_t *mutex d ) {38 d ->state = BARGE;37 void barge( global_data_t & mutex d ) { 38 d.state = BARGE; 39 39 } 40 40 41 41 thread Barger {}; 42 42 43 void main( Barger *this ) {43 void main( Barger & this ) { 44 44 while( !all_done ) { 45 barge( &data );45 barge( data ); 46 46 yield(); 47 47 } … … 50 50 //------------------------------------------------------------------------------ 51 51 // Waiting logic 52 bool wait( global_t * mutex m, global_data_t *mutex d ) {52 bool wait( global_t & mutex m, global_data_t & mutex d ) { 53 53 wait( &cond ); 54 if( d ->state != SIGNAL ) {54 if( d.state != SIGNAL ) { 55 55 sout | "ERROR barging!" | endl; 56 56 } 57 57 58 d ->counter++;58 d.counter++; 59 59 60 if( (d ->counter % 1000) == 0 ) sout | d->counter | endl;60 if( (d.counter % 1000) == 0 ) sout | d.counter | endl; 61 61 62 return d ->counter < N;62 return d.counter < N; 63 63 } 64 64 65 65 thread Waiter {}; 66 66 67 void main( Waiter *this ) {68 while( wait( &mut, &data ) ) { yield(); }67 void main( Waiter & this ) { 68 while( wait( mut, data ) ) { yield(); } 69 69 } 70 70 … … 72 72 //------------------------------------------------------------------------------ 73 73 // Signalling logic 74 void signal( condition * cond, global_t * mutex a, global_data_t *mutex b ) {75 b ->state = SIGNAL;74 void signal( condition * cond, global_t & mutex a, global_data_t & mutex b ) { 75 b.state = SIGNAL; 76 76 signal( cond ); 77 77 } 78 78 79 void logic( global_t *mutex a ) {80 signal( &cond, a, &data );79 void logic( global_t & mutex a ) { 80 signal( &cond, a, data ); 81 81 82 82 yield( (unsigned)rand48() % 10 ); … … 91 91 thread Signaller {}; 92 92 93 void main( Signaller *this ) {93 void main( Signaller & this ) { 94 94 while( !all_done ) { 95 logic( &mut );95 logic( mut ); 96 96 yield(); 97 97 } -
src/tests/sched-int-wait.c
r8499c707 r83a071f9 27 27 //---------------------------------------------------------------------------------------------------- 28 28 // Tools 29 void signal( condition * cond, global_t * mutex a, global_t *mutex b ) {29 void signal( condition * cond, global_t & mutex a, global_t & mutex b ) { 30 30 signal( cond ); 31 31 } 32 32 33 void signal( condition * cond, global_t * mutex a, global_t * mutex b, global_t *mutex c ) {33 void signal( condition * cond, global_t & mutex a, global_t & mutex b, global_t & mutex c ) { 34 34 signal( cond ); 35 35 } 36 36 37 void wait( condition * cond, global_t * mutex a, global_t *mutex b ) {37 void wait( condition * cond, global_t & mutex a, global_t & mutex b ) { 38 38 wait( cond ); 39 39 } 40 40 41 void wait( condition * cond, global_t * mutex a, global_t * mutex b, global_t *mutex c ) {41 void wait( condition * cond, global_t & mutex a, global_t & mutex b, global_t & mutex c ) { 42 42 wait( cond ); 43 43 } … … 45 45 //---------------------------------------------------------------------------------------------------- 46 46 // Signaler 47 void main( Signaler *this ) {47 void main( Signaler & this ) { 48 48 49 49 while( waiter_left != 0 ) { … … 51 51 switch( action ) { 52 52 case 0: 53 signal( &condABC, &globalA, &globalB, &globalC );53 signal( &condABC, globalA, globalB, globalC ); 54 54 break; 55 55 case 1: 56 signal( &condAB , &globalA, &globalB );56 signal( &condAB , globalA, globalB ); 57 57 break; 58 58 case 2: 59 signal( &condBC , &globalB, &globalC );59 signal( &condBC , globalB, globalC ); 60 60 break; 61 61 case 3: 62 signal( &condAC , &globalA, &globalC );62 signal( &condAC , globalA, globalC ); 63 63 break; 64 64 default: … … 72 72 //---------------------------------------------------------------------------------------------------- 73 73 // Waiter ABC 74 void main( WaiterABC *this ) {74 void main( WaiterABC & this ) { 75 75 for( int i = 0; i < N; i++ ) { 76 wait( &condABC, &globalA, &globalB, &globalC );76 wait( &condABC, globalA, globalB, globalC ); 77 77 } 78 78 … … 82 82 //---------------------------------------------------------------------------------------------------- 83 83 // Waiter AB 84 void main( WaiterAB *this ) {84 void main( WaiterAB & this ) { 85 85 for( int i = 0; i < N; i++ ) { 86 wait( &condAB , &globalA, &globalB );86 wait( &condAB , globalA, globalB ); 87 87 } 88 88 … … 92 92 //---------------------------------------------------------------------------------------------------- 93 93 // Waiter AC 94 void main( WaiterAC *this ) {94 void main( WaiterAC & this ) { 95 95 for( int i = 0; i < N; i++ ) { 96 wait( &condAC , &globalA, &globalC );96 wait( &condAC , globalA, globalC ); 97 97 } 98 98 … … 102 102 //---------------------------------------------------------------------------------------------------- 103 103 // Waiter BC 104 void main( WaiterBC *this ) {104 void main( WaiterBC & this ) { 105 105 for( int i = 0; i < N; i++ ) { 106 wait( &condBC , &globalB, &globalC );106 wait( &condBC , globalB, globalC ); 107 107 } 108 108 -
src/tests/thread.c
r8499c707 r83a071f9 7 7 thread Second { semaphore* lock; }; 8 8 9 void ?{}( First & this, semaphore * lock ) { this.lock =lock; }10 void ?{}( Second & this, semaphore * lock ) { this.lock =lock; }9 void ?{}( First & this, semaphore & lock ) { this.lock = &lock; } 10 void ?{}( Second & this, semaphore & lock ) { this.lock = &lock; } 11 11 12 void main(First *this) {12 void main(First& this) { 13 13 for(int i = 0; i < 10; i++) { 14 14 sout | "First : Suspend No." | i + 1 | endl; 15 15 yield(); 16 16 } 17 V(this ->lock);17 V(this.lock); 18 18 } 19 19 20 void main(Second *this) {21 P(this ->lock);20 void main(Second& this) { 21 P(this.lock); 22 22 for(int i = 0; i < 10; i++) { 23 23 sout | "Second : Suspend No." | i + 1 | endl; … … 33 33 processor p; 34 34 { 35 First f = { &lock };36 Second s = { &lock };35 First f = { lock }; 36 Second s = { lock }; 37 37 } 38 38 }
Note:
See TracChangeset
for help on using the changeset viewer.