Skip to content

Commit

Permalink
#107 nullptr crash in coro::mutex::unlock() during stress test (#108)
Browse files Browse the repository at this point in the history
Moved the awaiting coroutine assignment to before appending the scoped lock object to the list of waiters.
  • Loading branch information
jbaldwin authored Nov 6, 2021
1 parent 285416b commit 6bf5e25
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ auto mutex::lock_operation::await_ready() const noexcept -> bool

auto mutex::lock_operation::await_suspend(std::coroutine_handle<> awaiting_coroutine) noexcept -> bool
{
m_awaiting_coroutine = awaiting_coroutine;
void* current = m_mutex.m_state.load(std::memory_order::acquire);
void* new_value;

Expand All @@ -57,10 +58,10 @@ auto mutex::lock_operation::await_suspend(std::coroutine_handle<> awaiting_corou
if (current == unlocked_value)
{
std::atomic_thread_fence(std::memory_order::acquire);
m_awaiting_coroutine = nullptr; // nothing to await later since this doesn't suspend
return false;
}

m_awaiting_coroutine = awaiting_coroutine;
return true;
}

Expand Down

0 comments on commit 6bf5e25

Please sign in to comment.