Changeset 5407cdc for tests/concurrent
- Timestamp:
- Apr 28, 2021, 4:56:50 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, stuck-waitfor-destruct
- Children:
- 8d66610
- Parents:
- feacef9 (diff), b7fd2db6 (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:
-
- 6 added
- 3 edited
-
.expect/clib_tls.txt (added)
-
.expect/semaphore.txt (added)
-
.expect/spinaphore.txt (added)
-
clib.c (modified) (6 diffs)
-
clib_tls.c (added)
-
coroutineYield.cfa (modified) (1 diff)
-
futures/multi.cfa (modified) (4 diffs)
-
semaphore.cfa (added)
-
spinaphore.cfa (added)
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/clib.c
rfeacef9 r5407cdc 1 #include <clib/cfathread.h>2 3 1 #include <stdio.h> 4 2 #include <stdlib.h> 3 #include <clib/cfathread.h> 4 #include <bits/defs.hfa> 5 6 extern "C" { 7 void _exit(int status); 8 } 5 9 6 10 thread_local struct drand48_data buffer = { 0 }; … … 15 19 cfathread_t volatile blocked[blocked_size]; 16 20 17 void Worker( cfathread_t this) {21 void * Worker( void * ) { 18 22 for(int i = 0; i < 1000; i++) { 19 23 int idx = myrand() % blocked_size; … … 22 26 cfathread_unpark( thrd ); 23 27 } else { 24 cfathread_t thrd = __atomic_exchange_n(&blocked[idx], this, __ATOMIC_SEQ_CST);28 cfathread_t thrd = __atomic_exchange_n(&blocked[idx], cfathread_self(), __ATOMIC_SEQ_CST); 25 29 cfathread_unpark( thrd ); 26 30 cfathread_park(); … … 28 32 } 29 33 printf("Done\n"); 34 return NULL; 30 35 } 31 36 32 37 volatile bool stop; 33 void Unparker( cfathread_t this) {38 void * Unparker( void * ) { 34 39 while(!stop) { 35 40 int idx = myrand() % blocked_size; … … 42 47 } 43 48 printf("Done Unparker\n"); 49 return NULL; 44 50 } 45 51 … … 51 57 } 52 58 53 cfathread_setproccnt( 4 ); 54 cfathread_t u = cfathread_create( Unparker ); 59 cfathread_cluster_t cl = cfathread_cluster_self(); 60 61 cfathread_cluster_add_worker( cl, NULL, NULL, NULL ); 62 cfathread_cluster_add_worker( cl, NULL, NULL, NULL ); 63 cfathread_cluster_add_worker( cl, NULL, NULL, NULL ); 64 65 cfathread_attr_t attr; 66 cfathread_attr_init(&attr); 67 cfathread_attr_setcluster(&attr, cl); 68 69 cfathread_t u; 70 cfathread_create( &u, &attr, Unparker, NULL ); 55 71 { 56 72 cfathread_t t[20]; 57 73 for(int i = 0; i < 20; i++) { 58 t[i] = cfathread_create( Worker);74 cfathread_create( &t[i], &attr, Worker, NULL ); 59 75 } 60 76 for(int i = 0; i < 20; i++) { 61 cfathread_join( t[i] );77 cfathread_join( t[i], NULL ); 62 78 } 63 79 } 64 80 stop = true; 65 cfathread_join(u); 66 cfathread_setproccnt( 1 ); 81 cfathread_join(u, NULL); 82 cfathread_attr_destroy(&attr); 83 fflush(stdout); 84 _exit(0); 67 85 } -
tests/concurrent/coroutineYield.cfa
rfeacef9 r5407cdc 38 38 39 39 40 Coroutine c; 40 41 int main(int argc, char* argv[]) { 41 Coroutine c;42 42 for(int i = 0; TEST(i < N); i++) { 43 43 #if !defined(TEST_FOREVER) -
tests/concurrent/futures/multi.cfa
rfeacef9 r5407cdc 5 5 6 6 thread Server { 7 int cnt, iteration;7 int pending, done, iteration; 8 8 multi_future(int) * request; 9 9 }; 10 10 11 11 void ?{}( Server & this ) { 12 this.cnt = 0; 12 ((thread&)this){"Server Thread"}; 13 this.pending = 0; 14 this.done = 0; 13 15 this.iteration = 0; 14 16 this.request = 0p; … … 16 18 17 19 void ^?{}( Server & mutex this ) { 18 assert(this. cnt== 0);19 this.request = 0p;20 assert(this.pending == 0); 21 this.request = 0p; 20 22 } 21 23 … … 24 26 } 25 27 26 void process( Server & mutex this ) { 27 fulfil( *this.request, this.iteration ); 28 this.iteration++; 28 void call( Server & mutex this ) { 29 this.pending++; 29 30 } 30 31 31 void call( Server & mutex this ) {32 this. cnt++;32 void finish( Server & mutex this ) { 33 this.done++; 33 34 } 34 35 35 void finish( Server & mutex this ) { }36 37 36 void main( Server & this ) { 37 MAIN_LOOP: 38 38 for() { 39 39 waitfor( ^?{} : this ) { 40 40 break; 41 41 } 42 or when( this.cnt < NFUTURES ) waitfor( call: this ) { 43 if (this.cnt == NFUTURES) { 44 process(this); 42 or waitfor( call: this ) { 43 if (this.pending != NFUTURES) { continue MAIN_LOOP; } 44 45 this.pending = 0; 46 fulfil( *this.request, this.iteration ); 47 this.iteration++; 48 49 for(NFUTURES) { 50 waitfor( finish: this ); 45 51 } 46 } 47 or waitfor( finish: this ) { 48 if (this.cnt == NFUTURES) { 49 reset( *this.request ); 50 this.cnt = 0; 51 } 52 53 reset( *this.request ); 54 this.done = 0; 52 55 } 53 56 } … … 57 60 Server * the_server; 58 61 thread Worker {}; 62 void ?{}(Worker & this) { 63 ((thread&)this){"Worker Thread"}; 64 } 65 59 66 multi_future(int) * shared_future; 60 67
Note:
See TracChangeset
for help on using the changeset viewer.