c - Initialise thread pool -
as part of hw assignment, i'm implement thread pool in ansi c using pthreads.
i'm having difficulty understanding how initialise thread pool. think idea initialise pool thread sleeps until job do, i'm not sure how implement this.
create queue of jobs (this simple linked list), protected mutex. pair condition variable broadcast signalled when job added queue. threads can wait job code like:
pthread_mutex_lock(&queue_lock); while (queue_is_empty) pthread_cond_wait(&queue_cond, &queue_lock); job = pop_from_queue(); pthread_mutex_unlock(&queue_lock);
Comments
Post a Comment