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

Fixed possible memory order bug #84

Closed
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions BS_thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ class [[nodiscard]] thread_pool
const std::scoped_lock tasks_lock(tasks_mutex);
tasks.push(task_function);
}

const std::lock_guard tasks_lock(tasks_mutex);
++tasks_total;
task_available_cv.notify_one();
}
Expand Down Expand Up @@ -535,8 +537,11 @@ class [[nodiscard]] thread_pool
*/
void destroy_threads()
{
running = false;
task_available_cv.notify_all();
{
const std::lock_guard tasks_locker(tasks_mutex);
running = false;
task_available_cv.notify_all();
}
for (concurrency_t i = 0; i < thread_count; ++i)
{
threads[i].join();
Expand Down
9 changes: 7 additions & 2 deletions BS_thread_pool_light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class [[nodiscard]] thread_pool_light
const std::scoped_lock tasks_lock(tasks_mutex);
tasks.push(task_function);
}

const std::lock_guard tasks_lock(tasks_mutex);
++tasks_total;
task_available_cv.notify_one();
}
Expand Down Expand Up @@ -221,8 +223,11 @@ class [[nodiscard]] thread_pool_light
*/
void destroy_threads()
{
running = false;
task_available_cv.notify_all();
{
const std::lock_guard tasks_locker( tasks_mutex );
running = false;
task_available_cv.notify_all();
}
for (concurrency_t i = 0; i < thread_count; ++i)
{
threads[i].join();
Expand Down