Skip to content
Merged
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
7 changes: 7 additions & 0 deletions src/fibers/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ void FiberMutex::lock() noexcept
// Spin briefly before suspending: if the owner is on another CPU and releases
// within ~500 ns, we avoid the full scheduler wakeup path.
// Skip if there are already waiters in the queue.
//
// The owner pointer is loaded from a stale snapshot of state, so by the time
// we call isFiberRunning the original owner may have unlocked, returned, and
// been recycled by the fiber pool into a different fiber. The pool never
// unmaps Fiber memory, so the load on owner->state is always safe; the worst
// case is a spurious 500 ns spin against the wrong fiber's state, after which
// lockHelper takes the slow path. No correctness consequence.
if (!currentState.hasWaiters)
{
Fiber * owner = reinterpret_cast<Fiber *>(currentState.owner);
Expand Down
Loading