Changes in tests/concurrent/clib.c [df65c0c:bb662027]
- File:
-
- 1 edited
-
tests/concurrent/clib.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/clib.c
rdf65c0c rbb662027 1 #include <clib/cfathread.h> 2 1 3 #include <stdio.h> 2 4 #include <stdlib.h> 3 #include <clib/cfathread.h>4 5 extern "C" {6 void _exit(int status);7 }8 5 9 6 thread_local struct drand48_data buffer = { 0 }; … … 18 15 cfathread_t volatile blocked[blocked_size]; 19 16 20 void * Worker( void *) {17 void Worker( cfathread_t this ) { 21 18 for(int i = 0; i < 1000; i++) { 22 19 int idx = myrand() % blocked_size; … … 25 22 cfathread_unpark( thrd ); 26 23 } else { 27 cfathread_t thrd = __atomic_exchange_n(&blocked[idx], cfathread_self(), __ATOMIC_SEQ_CST);24 cfathread_t thrd = __atomic_exchange_n(&blocked[idx], this, __ATOMIC_SEQ_CST); 28 25 cfathread_unpark( thrd ); 29 26 cfathread_park(); … … 31 28 } 32 29 printf("Done\n"); 33 return NULL;34 30 } 35 31 36 32 volatile bool stop; 37 void * Unparker( void *) {33 void Unparker( cfathread_t this ) { 38 34 while(!stop) { 39 35 int idx = myrand() % blocked_size; … … 46 42 } 47 43 printf("Done Unparker\n"); 48 return NULL;49 44 } 50 45 … … 56 51 } 57 52 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 ); 53 cfathread_setproccnt( 4 ); 54 cfathread_t u = cfathread_create( Unparker ); 65 55 { 66 56 cfathread_t t[20]; 67 57 for(int i = 0; i < 20; i++) { 68 cfathread_create( &t[i], NULL, Worker, NULL);58 t[i] = cfathread_create( Worker ); 69 59 } 70 60 for(int i = 0; i < 20; i++) { 71 cfathread_join( t[i] , NULL);61 cfathread_join( t[i] ); 72 62 } 73 63 } 74 64 stop = true; 75 cfathread_join(u, NULL); 76 fflush(stdout); 77 _exit(0); 65 cfathread_join(u); 66 cfathread_setproccnt( 1 ); 78 67 }
Note:
See TracChangeset
for help on using the changeset viewer.