Changeset 58fe85a for tests/concurrent
- Timestamp:
- Jan 7, 2021, 3:27:00 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 2b4daf2, 64aeca0
- Parents:
- 3c64c668 (diff), eef8dfb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- tests/concurrent
- Files:
-
- 19 added
- 12 edited
- 1 moved
-
.expect/clib.txt (added)
-
.expect/cluster.txt (added)
-
.expect/join.txt (added)
-
.expect/joinerror.sed (added)
-
.expect/monitor.txt (modified) (1 diff)
-
.expect/suspend_then.txt (added)
-
clib.c (added)
-
cluster.cfa (added)
-
coroutineYield.cfa (modified) (1 diff)
-
examples/.expect/datingService.txt (modified) (1 diff)
-
examples/boundedBufferEXT.cfa (modified) (2 diffs)
-
examples/datingService.cfa (modified) (4 diffs)
-
futures/.expect/abandon.txt (added)
-
futures/.expect/basic.txt (added)
-
futures/.expect/multi.txt (added)
-
futures/.expect/typed.txt (added)
-
futures/abandon.cfa (added)
-
futures/basic.cfa (added)
-
futures/multi.cfa (added)
-
futures/typed.cfa (added)
-
join.cfa (added)
-
joinerror.cfa (added)
-
monitor.cfa (modified) (1 diff)
-
park/.expect/force_preempt.txt (modified) (1 diff)
-
park/.expect/start_parked.txt (added)
-
park/contention.cfa (modified) (1 diff)
-
park/force_preempt.cfa (modified) (4 diffs)
-
park/start_parked.cfa (added)
-
signal/block.cfa (modified) (1 diff)
-
signal/disjoint.cfa (modified) (6 diffs)
-
suspend_then.cfa (moved) (moved from tests/concurrent/coroutineThen.cfa ) (6 diffs)
-
waitfor/when.cfa (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/.expect/monitor.txt
r3c64c668 r58fe85a 1 40000001 3000000 -
tests/concurrent/coroutineYield.cfa
r3c64c668 r58fe85a 33 33 sout | "Coroutine 2"; 34 34 #endif 35 suspend ();35 suspend; 36 36 } 37 37 } -
tests/concurrent/examples/.expect/datingService.txt
r3c64c668 r58fe85a 1 done -
tests/concurrent/examples/boundedBufferEXT.cfa
r3c64c668 r58fe85a 1 1 // 2 2 // Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo 3 // 3 // 4 4 // The contents of this file are covered under the licence agreement in the 5 5 // file "LICENCE" distributed with Cforall. … … 87 87 } 88 88 89 enum { Prods = 4, Cons = 5 }; 90 Producer * prods[Prods]; 91 Consumer * cons[Cons]; 92 89 93 int main() { 90 94 Buffer(int) buffer; 91 enum { Prods = 4, Cons = 5 };92 Producer * prods[Prods];93 Consumer * cons[Cons];94 95 int sums[Cons]; 95 96 int i; -
tests/concurrent/examples/datingService.cfa
r3c64c668 r58fe85a 10 10 // Created On : Mon Oct 30 12:56:20 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jun 21 11:32:34 201913 // Update Count : 3812 // Last Modified On : Sun Sep 27 15:42:25 2020 13 // Update Count : 40 14 14 // 15 15 … … 35 35 signal_block( Boys[ccode] ); // restart boy to set phone number 36 36 } // if 37 // sout | "Girl:" | PhoneNo | "is dating Boy at" | BoyPhoneNo | "with ccode" | ccode;37 // sout | "Girl:" | PhoneNo | "is dating Boy at" | BoyPhoneNo | "with ccode" | ccode; 38 38 return BoyPhoneNo; 39 39 } // DatingService girl … … 47 47 signal_block( Girls[ccode] ); // restart girl to set phone number 48 48 } // if 49 // sout | " Boy:" | PhoneNo | "is dating Girl" | GirlPhoneNo | "with ccode" | ccode;49 // sout | " Boy:" | PhoneNo | "is dating Girl" | GirlPhoneNo | "with ccode" | ccode; 50 50 return GirlPhoneNo; 51 51 } // DatingService boy … … 108 108 if ( girlck[ boyck[i] ] != boyck[ girlck[i] ] ) abort(); 109 109 } // for 110 111 printf( "done\n" ); // non-empty .expect file 110 112 } // main 111 113 -
tests/concurrent/monitor.cfa
r3c64c668 r58fe85a 29 29 30 30 void main( MyThread & this ) { 31 for(int i = 0; i < 1_000_000; i++) {31 for(int i = 0; i < 750_000; i++) { 32 32 increment( global ); 33 33 } -
tests/concurrent/park/.expect/force_preempt.txt
r3c64c668 r58fe85a 1 0 Calling unpark 0 2 1 Calling unpark 0 3 2 Calling unpark 0 4 3 Calling unpark 0 5 4 Calling unpark 0 6 0 Parking 0 7 0 Unparked 0 8 0 Calling unpark 1 9 1 Parking 0 10 1 Unparked 0 11 1 Calling unpark 1 12 2 Parking 0 13 2 Unparked 0 14 2 Calling unpark 1 15 3 Parking 0 16 3 Unparked 0 17 3 Calling unpark 1 18 4 Parking 0 19 4 Unparked 0 20 4 Calling unpark 1 21 0 Parking 1 22 0 Unparked 1 23 0 Calling unpark 2 24 1 Parking 1 25 1 Unparked 1 26 1 Calling unpark 2 27 2 Parking 1 28 2 Unparked 1 29 2 Calling unpark 2 30 3 Parking 1 31 3 Unparked 1 32 3 Calling unpark 2 33 4 Parking 1 34 4 Unparked 1 35 4 Calling unpark 2 36 0 Parking 2 37 0 Unparked 2 38 0 Calling unpark 3 39 1 Parking 2 40 1 Unparked 2 41 1 Calling unpark 3 42 2 Parking 2 43 2 Unparked 2 44 2 Calling unpark 3 45 3 Parking 2 46 3 Unparked 2 47 3 Calling unpark 3 48 4 Parking 2 49 4 Unparked 2 50 4 Calling unpark 3 51 0 Parking 3 52 0 Unparked 3 53 0 Calling unpark 4 54 1 Parking 3 55 1 Unparked 3 56 1 Calling unpark 4 57 2 Parking 3 58 2 Unparked 3 59 2 Calling unpark 4 60 3 Parking 3 61 3 Unparked 3 62 3 Calling unpark 4 63 4 Parking 3 64 4 Unparked 3 65 4 Calling unpark 4 66 0 Parking 4 67 0 Unparked 4 68 1 Parking 4 69 1 Unparked 4 70 2 Parking 4 71 2 Unparked 4 72 3 Parking 4 73 3 Unparked 4 74 4 Parking 4 75 4 Unparked 4 1 done -
tests/concurrent/park/contention.cfa
r3c64c668 r58fe85a 24 24 } else { 25 25 Thread * thrd = __atomic_exchange_n(&blocked[idx], &this, __ATOMIC_SEQ_CST); 26 unpark( *thrd );26 unpark( *thrd ); 27 27 park(); 28 28 } -
tests/concurrent/park/force_preempt.cfa
r3c64c668 r58fe85a 16 16 } 17 17 18 thread Waiter;19 18 thread Waiter {}; 20 21 19 22 20 volatile int count = 0; … … 25 23 // Get a unique id 26 24 int id = __atomic_fetch_add(&count, 1, __ATOMIC_SEQ_CST); 25 int id_hash = id | (id << 8) | (id << 16) | (id << 24); 26 int mask = 0xCAFEBABA; 27 27 28 28 for(int i = 0; i < 5; i++) { 29 assert(mask == 0xCAFEBABA); 30 29 31 // Unpark this thread, don't force a yield 30 sout | id | "Calling unpark" | i; 31 unpark(this); 32 unpark( this ); 33 assert(mask == 0xCAFEBABA); 34 35 // Hash the mask to make sure no one else messes with them 36 mask ^= id_hash; 37 assert(mask == (id_hash ^ 0xCAFEBABA)); 32 38 33 39 // Force a preemption before the call to park … … 36 42 37 43 // Park this thread, 38 sout | id | "Parking" | i;44 assert(mask == (id_hash ^ 0xCAFEBABA)); 39 45 park(); 40 sout | id | "Unparked" | i; 46 assert(mask == (id_hash ^ 0xCAFEBABA)); 47 48 // Reset the hash and recheck it 49 mask ^= id_hash; 50 assert(mask == 0xCAFEBABA); 41 51 } 42 52 } … … 47 57 Waiter waiters[5]; 48 58 } 59 printf( "done\n" ); // non-empty .expect file 49 60 } -
tests/concurrent/signal/block.cfa
r3c64c668 r58fe85a 82 82 if( !is_empty( cond ) ) { 83 83 84 $thread * next = front( cond );84 $thread * next = ( $thread * ) front( cond ); 85 85 86 86 if( ! signal_block( cond ) ) { -
tests/concurrent/signal/disjoint.cfa
r3c64c668 r58fe85a 21 21 #endif 22 22 23 // This tests checks what happens when someone barges in the midle of the release 24 // of a bulk of monitors. 25 23 26 enum state_t { WAIT, SIGNAL, BARGE }; 24 27 25 28 monitor global_t {}; 26 global_t mut;27 29 28 30 monitor global_data_t; … … 33 35 int counter; 34 36 state_t state; 35 } data; 37 }; 38 39 // Use a global struct because the order needs to match with Signaller thread 40 struct { 41 global_t mut; 42 global_data_t data; 43 } globals; 36 44 37 45 condition cond; … … 40 48 41 49 void ?{}( global_data_t & this ) { 42 this.counter = =0;50 this.counter = 0; 43 51 this.state = BARGE; 44 52 } … … 53 61 54 62 thread Barger {}; 63 void ?{}( Barger & this ) { 64 ((thread&)this){ "Barger Thread" }; 65 } 55 66 56 67 void main( Barger & this ) { 57 68 while( !all_done ) { 58 barge( data );69 barge( globals.data ); 59 70 yield(); 60 71 } … … 78 89 79 90 thread Waiter {}; 91 void ?{}( Waiter & this ) { 92 ((thread&)this){ "Waiter Thread" }; 93 } 80 94 81 95 void main( Waiter & this ) { 82 while( wait( mut,data ) ) { KICK_WATCHDOG; yield(); }96 while( wait( globals.mut, globals.data ) ) { KICK_WATCHDOG; yield(); } 83 97 } 84 98 … … 92 106 93 107 void logic( global_t & mutex a ) { 94 signal( cond, a, data );108 signal( cond, a, globals.data ); 95 109 96 110 yield( random( 10 ) ); 97 111 98 112 //This is technically a mutual exclusion violation but the mutex monitor protects us 99 bool running = TEST( data.counter < N) &&data.counter > 0;100 if( data.state != SIGNAL && running ) {101 sout | "ERROR Eager signal" | data.state;113 bool running = TEST(globals.data.counter < N) && globals.data.counter > 0; 114 if( globals.data.state != SIGNAL && running ) { 115 sout | "ERROR Eager signal" | globals.data.state; 102 116 } 103 117 } 104 118 105 119 thread Signaller {}; 120 void ?{}( Signaller & this ) { 121 ((thread&)this){ "Signaller Thread" }; 122 } 106 123 107 124 void main( Signaller & this ) { 108 125 while( !all_done ) { 109 logic( mut );126 logic( globals.mut ); 110 127 yield(); 111 128 } -
tests/concurrent/suspend_then.cfa
r3c64c668 r58fe85a 1 1 #include <fstream.hfa> 2 2 #include <kernel.hfa> 3 #include <monitor.hfa>4 3 #include <thread.hfa> 5 4 #include <time.hfa> … … 10 9 #include "long_tests.hfa" 11 10 12 #ifndef PREEMPTION_RATE13 #define PREEMPTION_RATE 10`ms14 #endif15 16 11 Duration default_preemption() { 17 return PREEMPTION_RATE;12 return 0; 18 13 } 19 14 … … 26 21 #if !defined(TEST_FOREVER) 27 22 static inline void print(const char * const text ) { 28 write( STD ERR_FILENO, text, strlen(text) );23 write( STDOUT_FILENO, text, strlen(text) ); 29 24 } 30 25 #else … … 32 27 #endif 33 28 34 coroutine Coroutine {};29 generator Coroutine { int i; }; 35 30 36 31 volatile bool done = false; … … 49 44 50 45 void main(Coroutine& this) { 51 suspend(); 52 for(int i = 0; TEST(i < N); i++) { 46 this.i = 0; 47 suspend; 48 for(;TEST(this.i < N); this.i++) { 53 49 54 print("C - Suspending ");55 void publish(){56 print("C - Publishing ");50 print("C - Suspending\n"); 51 suspend{ 52 print("C - Publishing\n"); 57 53 assert(!the_cor); 58 54 store( this ); 59 55 } 60 suspend_then(publish);61 56 assert(!the_cor); 62 print("C oroutine 2");57 print("C - Back\n"); 63 58 KICK_WATCHDOG; 64 59 yield(); 65 60 } 66 61 done = true; 67 suspend ();62 suspend; 68 63 } 69 64 … … 77 72 if(!mine) continue; 78 73 79 print("T - took ");74 print("T - took\n"); 80 75 resume(*mine); 81 print("T - back");82 76 } 83 77 } -
tests/concurrent/waitfor/when.cfa
r3c64c668 r58fe85a 57 57 58 58 void arbiter( global_t & mutex this ) { 59 // There is a race at start where callers can get in before the arbiter. 60 // It doesn't really matter here so just restart the loop correctly and move on 61 this.last_call = 6; 62 59 63 for( int i = 0; i < N; i++ ) { 60 64 when( this.last_call == 6 ) waitfor( call1 : this ) { if( this.last_call != 1) { serr | "Expected last_call to be 1 got" | this.last_call; } }
Note:
See TracChangeset
for help on using the changeset viewer.