Example #1
0
void thread_pool_example(){
	int i;
	struct thread_pool pool;
	thread_pool_init(&pool, 8);
	thread_sleep(100);
	for(i=0;i<20;i++){
		thread_pool_add_task(&pool, task, NULL, i);
	}
	thread_sleep(1000);
	thread_pool_destory(&pool);
}
Example #2
0
int main()
{
    pool_t pool;
    thread_pool_init(&pool, 5);
    thread_pool_start(&pool);

    srand(10086);
    while(1) {
        task_t task;
        task.thread_callback = task_func;
        task.arg = (void *)(rand() % 100);
        thread_pool_add_task(&pool, task);
        printf("ThreadPool size: %d, TaskQueue size: %d\n", (int)pool.size_, (int)pool.queue_.size_);
    }
    thread_pool_stop(&pool);
    thread_pool_destroy(&pool);
    return 0;
}