Changes in tests/concurrent/clib.c [bb662027:a5e7233]
- File:
-
- 1 edited
-
tests/concurrent/clib.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/clib.c
rbb662027 ra5e7233 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 }
Note:
See TracChangeset
for help on using the changeset viewer.