Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrent/clib.c

    rbb662027 ra5e7233  
    1 #include <clib/cfathread.h>
    2 
    31#include <stdio.h>
    42#include <stdlib.h>
     3#include <clib/cfathread.h>
     4#include <bits/defs.hfa>
     5
     6extern "C" {
     7void _exit(int status);
     8}
    59
    610thread_local struct drand48_data buffer = { 0 };
     
    1519cfathread_t volatile blocked[blocked_size];
    1620
    17 void Worker( cfathread_t this ) {
     21void * Worker( void * ) {
    1822        for(int i = 0; i < 1000; i++) {
    1923                int idx = myrand() % blocked_size;
     
    2226                        cfathread_unpark( thrd );
    2327                } 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);
    2529                        cfathread_unpark( thrd );
    2630                        cfathread_park();
     
    2832        }
    2933        printf("Done\n");
     34        return NULL;
    3035}
    3136
    3237volatile bool stop;
    33 void Unparker( cfathread_t this ) {
     38void * Unparker( void * ) {
    3439        while(!stop) {
    3540                int idx = myrand() % blocked_size;
     
    4247        }
    4348        printf("Done Unparker\n");
     49        return NULL;
    4450}
    4551
     
    5157        }
    5258
    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 );
    5571        {
    5672                cfathread_t t[20];
    5773                for(int i = 0; i < 20; i++) {
    58                         t[i] = cfathread_create( Worker );
     74                        cfathread_create( &t[i], &attr, Worker, NULL );
    5975                }
    6076                for(int i = 0; i < 20; i++) {
    61                         cfathread_join( t[i] );
     77                        cfathread_join( t[i], NULL );
    6278                }
    6379        }
    6480        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);
    6785}
Note: See TracChangeset for help on using the changeset viewer.