9 static const int POOLSIZE = 100;
11 static MemPool* barPool;
12 static MemPool* bazPool;
13 static MemPool* fooPool;
34 void* workerMain( void* arg ) {
36 struct foo* f = (struct foo*)arg;
38 f->z = f->br->x + f->bz->y;
40 poolfree( barPool, f->br );
41 poolfree( bazPool, f->bz );
55 int numThreads = 10000;
56 pthread_t threads[numThreads];
61 barPool = poolcreate( sizeof( struct bar ), POOLSIZE );
62 bazPool = poolcreate( sizeof( struct baz ), POOLSIZE );
63 fooPool = poolcreate( sizeof( struct foo ), POOLSIZE );
65 pthread_attr_init( &attr );
66 pthread_attr_setdetachstate( &attr,
67 PTHREAD_CREATE_JOINABLE );
70 for( i = 0; i < numThreads; ++i ) {
72 br = poolalloc( barPool );
73 bz = poolalloc( bazPool );
74 f = poolalloc( fooPool );
82 pthread_create( &(threads[i]),
98 for( i = 0; i < numThreads; ++i ) {
101 pthread_join( threads[i],
105 poolfree( fooPool, f );
107 if( i % 1000 == 0 ) {
112 printf( "\nTotal=%d\n", total );