Skip to content
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

Bugfix: wait_for_tasks should handle spurious wakeups #75

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/thread_pool/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ namespace dp {
* @details This function will block until all tasks have been completed.
*/
void wait_for_tasks() {
if (in_flight_tasks_.load(std::memory_order_acquire) > 0) {
// must be a while loop to ignore spurious wake-ups
while (in_flight_tasks_.load(std::memory_order_acquire) > 0) {
// wait for all tasks to finish
threads_complete_signal_.wait(false);
}
Expand Down
Loading