Update example.c

without the wait the 40 tasks will not have time to complete
This commit is contained in:
shaun 2017-12-30 01:26:31 -05:00 committed by GitHub
parent 430251cb65
commit ebe78873c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,16 +13,11 @@
#include <stdio.h> #include <stdio.h>
#include <pthread.h> #include <pthread.h>
#include <stdint.h>
#include "thpool.h" #include "thpool.h"
void task(void *arg){
void task1(){ printf("Thread #%u working on %d\n", (int)pthread_self(), (int) arg);
printf("Thread #%u working on task1\n", (int)pthread_self());
}
void task2(){
printf("Thread #%u working on task2\n", (int)pthread_self());
} }
@ -33,11 +28,11 @@ int main(){
puts("Adding 40 tasks to threadpool"); puts("Adding 40 tasks to threadpool");
int i; int i;
for (i=0; i<20; i++){ for (i=0; i<40; i++){
thpool_add_work(thpool, (void*)task1, NULL); thpool_add_work(thpool, (void*)task, (void*)(uintptr_t)i);
thpool_add_work(thpool, (void*)task2, NULL);
}; };
thpool_wait(thpool);
puts("Killing threadpool"); puts("Killing threadpool");
thpool_destroy(thpool); thpool_destroy(thpool);