libresman
diff src/threadpool.c @ 11:bebc065a941f
doesn't work yet
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 07 Feb 2014 07:50:02 +0200 |
parents | 4d18498a0078 |
children | 84f55eab27cb |
line diff
1.1 --- a/src/threadpool.c Wed Feb 05 02:01:49 2014 +0200 1.2 +++ b/src/threadpool.c Fri Feb 07 07:50:02 2014 +0200 1.3 @@ -37,6 +37,11 @@ 1.4 1.5 memset(tpool, 0, sizeof *tpool); 1.6 1.7 + 1.8 + pthread_mutex_init(&tpool->work_lock, 0); 1.9 + pthread_cond_init(&tpool->work_cond, 0); 1.10 + 1.11 + 1.12 if(num_threads <= 0) { 1.13 num_threads = get_processor_count(); 1.14 } 1.15 @@ -44,6 +49,11 @@ 1.16 1.17 printf("initializing thread pool with %d worker threads\n", num_threads); 1.18 1.19 + if(!(tpool->workers = malloc(num_threads * sizeof *tpool->workers))) { 1.20 + fprintf(stderr, "failed to create array of %d threads\n", num_threads); 1.21 + return -1; 1.22 + } 1.23 + 1.24 for(i=0; i<num_threads; i++) { 1.25 if(pthread_create(tpool->workers + i, 0, thread_func, tpool) == -1) { 1.26 fprintf(stderr, "%s: failed to create thread %d\n", __FUNCTION__, i); 1.27 @@ -51,9 +61,6 @@ 1.28 return -1; 1.29 } 1.30 } 1.31 - 1.32 - pthread_mutex_init(&tpool->work_lock, 0); 1.33 - pthread_cond_init(&tpool->work_cond, 0); 1.34 return 0; 1.35 } 1.36