-
Notifications
You must be signed in to change notification settings - Fork 253
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
Fix a race in check_pausing test. #42
Conversation
Thanks! I will incorporate the exit code into v3.0.0, which will be released soon. Regarding |
The root problem is that setting Suppose we have only 2 threads, worker thread (W) and test thread (T). We may have the following execution sequence:
So the task added after setting |
Thanks for the clarification. The effect of the statement You are correct that if But in any case, in the test program, |
In deed the race I mentioned previously is unlikely to happen in this test, since the test thread has print between setting pause to For me, the problem is caused by pop waiting on condition variable, which is introduced in my code change. The execution sequence is as follows:
For me, I'm planning to implement work thread local queue and work stealing, remove all sleep except in paused mode. It will be a big change which I can't expect full acceptance in this project. But this small change can address the theoratical possible race, and maybe help other people who's doing something similar. That's why I send this PR. |
Thanks, I do appreciate your contribution! It sounds like what you're saying is that this change is only needed for your modified version of the library, so I'm not sure there's benefit in adding it to this library. In addition, v3.0.0 of the library, which will be released soon, will replace sleep with condition variables (or possibly something else, I'm still testing different options) and therefore the pause mechanism will be rewritten too. There will be lots of other changes and improvements as well. I think you will find that v3.0.0 probably would work better for your needs. Thanks again :) |
Describe the changes
Two changes:
wait_and_pop
. Full changes on my fork's master branch.Thanks for this nice project. I'm new to concurrency support in C++, this project is clean and easy to understand, which motivates me to hack for my own requirements.
Testing
Have you tested the new code using the provided automated test program
thread_pool_test.cpp
and/or performed any other tests to ensure that it works correctly? If so, please provide information about the test system(s):