From ebe78873c0adc00e13e96dd96820b6d2b4e3f109 Mon Sep 17 00:00:00 2001 From: shaun Date: Sat, 30 Dec 2017 01:26:31 -0500 Subject: [PATCH] Update example.c without the wait the 40 tasks will not have time to complete --- example.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/example.c b/example.c index 0ac638f..e53d280 100644 --- a/example.c +++ b/example.c @@ -13,16 +13,11 @@ #include #include +#include #include "thpool.h" - -void task1(){ - printf("Thread #%u working on task1\n", (int)pthread_self()); -} - - -void task2(){ - printf("Thread #%u working on task2\n", (int)pthread_self()); +void task(void *arg){ + printf("Thread #%u working on %d\n", (int)pthread_self(), (int) arg); } @@ -33,11 +28,11 @@ int main(){ puts("Adding 40 tasks to threadpool"); int i; - for (i=0; i<20; i++){ - thpool_add_work(thpool, (void*)task1, NULL); - thpool_add_work(thpool, (void*)task2, NULL); + for (i=0; i<40; i++){ + thpool_add_work(thpool, (void*)task, (void*)(uintptr_t)i); }; + thpool_wait(thpool); puts("Killing threadpool"); thpool_destroy(thpool);