Changeset df65c0c for tests/concurrent
- Timestamp:
- Mar 12, 2021, 4:31:04 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 41ca6fa, e867b44
- Parents:
- a1538cd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/clib.c
ra1538cd rdf65c0c 1 #include <stdio.h> 2 #include <stdlib.h> 1 3 #include <clib/cfathread.h> 2 4 3 #include <stdio.h> 4 #include <stdlib.h> 5 extern "C" { 6 void _exit(int status); 7 } 5 8 6 9 thread_local struct drand48_data buffer = { 0 }; … … 15 18 cfathread_t volatile blocked[blocked_size]; 16 19 17 void Worker( cfathread_t this) {20 void * Worker( void * ) { 18 21 for(int i = 0; i < 1000; i++) { 19 22 int idx = myrand() % blocked_size; … … 22 25 cfathread_unpark( thrd ); 23 26 } else { 24 cfathread_t thrd = __atomic_exchange_n(&blocked[idx], this, __ATOMIC_SEQ_CST);27 cfathread_t thrd = __atomic_exchange_n(&blocked[idx], cfathread_self(), __ATOMIC_SEQ_CST); 25 28 cfathread_unpark( thrd ); 26 29 cfathread_park(); … … 28 31 } 29 32 printf("Done\n"); 33 return NULL; 30 34 } 31 35 32 36 volatile bool stop; 33 void Unparker( cfathread_t this) {37 void * Unparker( void * ) { 34 38 while(!stop) { 35 39 int idx = myrand() % blocked_size; … … 42 46 } 43 47 printf("Done Unparker\n"); 48 return NULL; 44 49 } 45 50 … … 51 56 } 52 57 53 cfathread_setproccnt( 4 ); 54 cfathread_t u = cfathread_create( Unparker ); 58 cfathread_cluster_t cl = cfathread_cluster_self(); 59 60 cfathread_cluster_add_worker( cl, NULL, NULL, NULL ); 61 cfathread_cluster_add_worker( cl, NULL, NULL, NULL ); 62 cfathread_cluster_add_worker( cl, NULL, NULL, NULL ); 63 cfathread_t u; 64 cfathread_create( &u, NULL, Unparker, NULL ); 55 65 { 56 66 cfathread_t t[20]; 57 67 for(int i = 0; i < 20; i++) { 58 t[i] = cfathread_create( Worker);68 cfathread_create( &t[i], NULL, Worker, NULL ); 59 69 } 60 70 for(int i = 0; i < 20; i++) { 61 cfathread_join( t[i] );71 cfathread_join( t[i], NULL ); 62 72 } 63 73 } 64 74 stop = true; 65 cfathread_join(u); 66 cfathread_setproccnt( 1 ); 75 cfathread_join(u, NULL); 76 fflush(stdout); 77 _exit(0); 67 78 }
Note: See TracChangeset
for help on using the changeset viewer.