diff --git a/player/main.c b/player/main.c index 3fa1edaf6baf216d5782875f36d002997fd391dd..7fec4ce19b462772187047a20627d8708bbcbb74 100644 --- a/player/main.c +++ b/player/main.c @@ -24,7 +24,20 @@ int main(int argc, char * argv[]) mpv_destruct(); #endif thread_pool_construct(10); + thread_pool_queue(func1, NULL); + thread_pool_queue(func1, NULL); + thread_pool_queue(func1, NULL); + thread_pool_queue(func1, NULL); + thread_pool_queue(func1, NULL); + thread_pool_queue(func1, NULL); + thread_pool_queue(func1, NULL); sleep(1); + thread_pool_queue(func1, NULL); + thread_pool_queue(func1, NULL); + thread_pool_queue(func1, NULL); + thread_pool_queue(func1, NULL); + thread_pool_queue(func1, NULL); + sleep(4); thread_pool_destruct(); return 0; } diff --git a/player/thread_pool.c b/player/thread_pool.c index 1246108a7efb0ad1ae633083130a7ad0a609346b..c9a0bd802703c835ab51c6f01ae9e81a87489631 100644 --- a/player/thread_pool.c +++ b/player/thread_pool.c @@ -43,11 +43,20 @@ void * worker_function(void * arg) { pthread_mutex_lock(¤t->mutex); - if (current->state == killed) + switch (current->state) { + case killed: pthread_mutex_unlock(¤t->mutex); pthread_mutex_destroy(¤t->mutex); pthread_exit(NULL); + break; + + case working: + current->function(current->arg); + current->state = waiting; + + default: + break; } pthread_mutex_unlock(¤t->mutex);