Skip to content

Commit

Permalink
reset the thread complete signal any time we add new tasks to an empt…
Browse files Browse the repository at this point in the history
…y queue.
  • Loading branch information
jtd-formlabs committed Jul 3, 2024
1 parent 56ce40b commit d6e2613
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions include/thread_pool/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ namespace dp {
}
auto i = *(i_opt);
unassigned_tasks_.fetch_add(1, std::memory_order_release);
in_flight_tasks_.fetch_add(1, std::memory_order_release);
const auto prev_in_flight = in_flight_tasks_.fetch_add(1, std::memory_order_release);

// reset the in flight signal if the list was previously empty
if (prev_in_flight == 0) {
threads_complete_signal_.store(false, std::memory_order_release);
}

tasks_[i].tasks.push_back(std::forward<Function>(f));
tasks_[i].signal.release();
}
Expand All @@ -250,7 +256,8 @@ namespace dp {
std::vector<ThreadType> threads_;
std::deque<task_item> tasks_;
dp::thread_safe_queue<std::size_t> priority_queue_;
std::atomic_int_fast64_t unassigned_tasks_{}, in_flight_tasks_{};
// guarantee these get zero-initialized
std::atomic_int_fast64_t unassigned_tasks_{0}, in_flight_tasks_{0};
std::atomic_bool threads_complete_signal_{false};
};

Expand Down

0 comments on commit d6e2613

Please sign in to comment.