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