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

Fix classic race with atomics + mutex #536

Merged
merged 1 commit into from
Feb 27, 2024
Merged
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
1 change: 1 addition & 0 deletions old_build/_deps/snitch-src
Submodule snitch-src added at 2f6230
12 changes: 8 additions & 4 deletions src/rpp/rpp/schedulers/new_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ namespace rpp::schedulers
if (!m_thread.joinable())
return;

// just notify
m_state->is_destroying.store(true, std::memory_order::seq_cst);
{
std::lock_guard lock{m_state->mutex};
m_state->is_destroying.store(true, std::memory_order::relaxed);
}
m_state->cv.notify_all();
m_thread.detach();
}
Expand All @@ -69,8 +71,10 @@ namespace rpp::schedulers
if (!m_thread.joinable())
return;

// just need atomicity, not guarding anything
m_state->is_disposed.store(true, std::memory_order::seq_cst);
{
std::lock_guard lock{m_state->mutex};
m_state->is_disposed.store(true, std::memory_order::relaxed);
}
m_state->cv.notify_all();

if (m_thread.get_id() != std::this_thread::get_id())
Expand Down
Loading