I have a pthread waiting on a condition variable using pthread_cond_wait()
. It\'s waiting for data from a queue structure that is filled by another thread. I want
Do you have access to the queue, and control of the object schema for enqueued items? If so, define a queue object type that when de-queued, instructs the thread that is processing the item to exit gracefully.
Now, to shut down these threads, simply post a number of these "quit" objects to the HEAD of the queue that corresponds to the number of threads that are servicing the queue, and join on the threads.
This seems much cleaner than the "nuclear option" of pthread_cancel/kill.