Skip to content

Commit

Permalink
Bugfix: wait_for_tasks should handle spurious wakeups
Browse files Browse the repository at this point in the history
  • Loading branch information
willkill07 authored Dec 10, 2024
1 parent bc10764 commit 779cc0e
Showing 1 changed file with 2 additions and 1 deletion.
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

0 comments on commit 779cc0e

Please sign in to comment.