You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

46 lines
885 B

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include "tiny_pool.h"
void demo_fun(void *i) {
int k = *(int*)i;
printf("demo func sleep %ds\n", k);
sleep(k);
printf("demo func %d wake up\n", k);
}
int main() {
// pthread_t tid;
pool_t *pool = tiny_pool_create(0);
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;
}