Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrent/clib.c

    rdf65c0c rbb662027  
     1#include <clib/cfathread.h>
     2
    13#include <stdio.h>
    24#include <stdlib.h>
    3 #include <clib/cfathread.h>
    4 
    5 extern "C" {
    6 void _exit(int status);
    7 }
    85
    96thread_local struct drand48_data buffer = { 0 };
     
    1815cfathread_t volatile blocked[blocked_size];
    1916
    20 void * Worker( void * ) {
     17void Worker( cfathread_t this ) {
    2118        for(int i = 0; i < 1000; i++) {
    2219                int idx = myrand() % blocked_size;
     
    2522                        cfathread_unpark( thrd );
    2623                } 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);
    2825                        cfathread_unpark( thrd );
    2926                        cfathread_park();
     
    3128        }
    3229        printf("Done\n");
    33         return NULL;
    3430}
    3531
    3632volatile bool stop;
    37 void * Unparker( void * ) {
     33void Unparker( cfathread_t this ) {
    3834        while(!stop) {
    3935                int idx = myrand() % blocked_size;
     
    4642        }
    4743        printf("Done Unparker\n");
    48         return NULL;
    4944}
    5045
     
    5651        }
    5752
    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 );
    6555        {
    6656                cfathread_t t[20];
    6757                for(int i = 0; i < 20; i++) {
    68                         cfathread_create( &t[i], NULL, Worker, NULL );
     58                        t[i] = cfathread_create( Worker );
    6959                }
    7060                for(int i = 0; i < 20; i++) {
    71                         cfathread_join( t[i], NULL );
     61                        cfathread_join( t[i] );
    7262                }
    7363        }
    7464        stop = true;
    75         cfathread_join(u, NULL);
    76         fflush(stdout);
    77         _exit(0);
     65        cfathread_join(u);
     66        cfathread_setproccnt( 1 );
    7867}
Note: See TracChangeset for help on using the changeset viewer.