3 changed files with 143 additions and 28 deletions
@ -1,23 +1,46 @@ |
|||||
#include <stdio.h> |
#include <stdio.h> |
||||
#include <pthread.h> |
#include <pthread.h> |
||||
|
#include <unistd.h> |
||||
#include "tiny_pool.h" |
#include "tiny_pool.h" |
||||
|
|
||||
void* demo_fun(void *i) { |
void demo_fun(void *i) { |
||||
printf("demo func -> %d\n", *(int*)i); |
|
||||
return NULL; |
int k = *(int*)i; |
||||
|
|
||||
|
printf("demo func sleep %ds\n", k); |
||||
|
|
||||
|
sleep(k); |
||||
|
|
||||
|
printf("demo func %d wake up\n", k); |
||||
|
|
||||
} |
} |
||||
|
|
||||
int main() { |
int main() { |
||||
|
|
||||
pthread_t tid; |
// pthread_t tid;
|
||||
|
|
||||
int d = 123; |
|
||||
|
|
||||
pool_t *pool = tiny_pool_create(0); |
pool_t *pool = tiny_pool_create(0); |
||||
|
|
||||
tiny_pool_submit(pool, demo_fun, (void*)&d); |
int dat[] = {1, 2, 3, 4, 5, 6}; |
||||
|
tiny_pool_submit(pool, demo_fun, (void*)&dat[0]); |
||||
|
tiny_pool_submit(pool, demo_fun, (void*)&dat[1]); |
||||
|
|
||||
|
printf("pool booting\n"); |
||||
|
tiny_pool_boot(pool); |
||||
|
printf("pool running\n"); |
||||
|
|
||||
|
printf("main thread sleep\n"); |
||||
|
sleep(5); |
||||
|
printf("main thread wake up\n"); |
||||
|
|
||||
|
tiny_pool_submit(pool, demo_fun, (void*)&dat[2]); |
||||
|
tiny_pool_submit(pool, demo_fun, (void*)&dat[3]); |
||||
|
tiny_pool_submit(pool, demo_fun, (void*)&dat[4]); |
||||
|
|
||||
|
// TODO: tiny pool join
|
||||
|
sleep(15); |
||||
|
|
||||
|
// TODO: tiny pool destroy
|
||||
|
|
||||
return 0; |
return 0; |
||||
} |
} |
||||
|
Loading…
Reference in new issue