-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dead locks #61
Comments
Hi, I found that the first problem is caused by the assignment of
Deadlock issue no longer occurs after moving For the second question, I tried with the modified code and found that this is not necessarily going to happen. And in the call stack, I don't understand why thpool_pause calls the printf function that should be called after thpool_pause?
And after I try to remove all puts and printf, the deadlock no longer occurs, will it be a problem with printf and puts? |
Hi Guys
Great idea to make a simple ANSI-C threadpool. The interface is great, but I have encountered numerous problems using it.
In your example:
After adding the work
for (i=0; i<20; i++){
thpool_add_work(thpool, (void*)task1, NULL);
thpool_add_work(thpool, (void*)task2, NULL);
};
if you add any of the following, you get a dead lock
thpool_pause(thpool);
thpool_resume(thpoll);
or
thpool_pause(thpool);
printf("nthreads alive: %d\n", thpool_num_threads_working(thpool));
sleep(1);
thpool_resume(thpool);
Accessing the variable num_threads_working is causing the error. Volatile does not imply atomic updates.
Another issue is all conditions and mutex'es. You are not allowed to reinitialize any of the two. This is possible in many ways. As long as only a single queue is supported, I can recommend using PTHREAD_COND_INITIALIZER and PTHREAD_MUTEX_INITIALIZER
I haven't been able to come up with a good solution supporting pause/resume.
Regards
Jens Munk
The text was updated successfully, but these errors were encountered: