Repository navigation
Fix macOS futex wake accounting with per-waiter notifications - #3637
chenBright wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
5 open issues
This test can become very slow/flaky under load: it may spin/yield for up to 5 seconds per… · New This test can become very slow/flaky under load: it may spin/yield for up to 5 seconds per… · Newfutex_wait_privatesetserrno = EAGAINon mismatched value (per the current implementation),… · New The loop bound256and deadline offset5000000Lare magic numbers that encode test policy… · New The loop bound256and deadline offset5000000Lare magic numbers that encode test policy… · New
What changed in this PR
This PR fixes macOS simulated futex wake accounting so repeated futex_wake_private() calls cannot “re-count” a waiter that was already notified but hasn’t resumed yet, preventing premature cessation of wakeups in higher-level schedulers.
Changes:
- Replace aggregate waiter counting with a per-waiter intrusive queue and per-waiter condition variables.
- Ensure notified waiters are removed from the queue at wake time; timed-out waiters remove themselves.
- Add regression tests covering double-count prevention, timeout interactions, and non-queued mismatched waits.
| File | Description |
|---|---|
| test/bthread_futex_unittest.cpp | Adds regression tests validating one-time wake accounting and timeout/non-queue behaviors. |
| src/bthread/sys_futex.cpp | Reworks simulated futex internals to track unnotified waiters explicitly and avoid double-counting. |
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
7 open issues
This relies onRemoveFromList()being safe to call even if the node has already been removed in… · New This relies onRemoveFromList()being safe to call even if the node has already been removed in… · NewINT_MAXis used in the new tests but this file doesn’t include a header that guarantees its… · New The “rescue” path can force the waiter to return-1/EAGAIN(by storingword=1before the waiter… · New The “rescue” path can force the waiter to return-1/EAGAIN(by storingword=1before the waiter… · NewINT_MAXis used in the new tests but this file doesn’t include a header that guarantees its… · NewINT_MAXis used in the new tests but this file doesn’t include a header that guarantees its… · New
5 resolved since last review
futex_wait_privatesetserrno = EAGAINon mismatched value (per the current implementation),… This test can become very slow/flaky under load: it may spin/yield for up to 5 seconds per… This test can become very slow/flaky under load: it may spin/yield for up to 5 seconds per… The loop bound256and deadline offset5000000Lare magic numbers that encode test policy… The loop bound256and deadline offset5000000Lare magic numbers that encode test policy…
Review effort: Lite
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
7 resolved since last review
INT_MAXis used in the new tests but this file doesn’t include a header that guarantees its…INT_MAXis used in the new tests but this file doesn’t include a header that guarantees its… The “rescue” path can force the waiter to return-1/EAGAIN(by storingword=1before the waiter… The “rescue” path can force the waiter to return-1/EAGAIN(by storingword=1before the waiter…INT_MAXis used in the new tests but this file doesn’t include a header that guarantees its… This relies onRemoveFromList()being safe to call even if the node has already been removed in… This relies onRemoveFromList()being safe to call even if the node has already been removed in…
Review effort: Lite
|
@wwbmmm PTAL. The remaining Copilot review comments have been evaluated and are either false positives or non-blocking suggestions that we will not adopt in this bugfix. No further code changes are needed. All 65 relevant tests passed, and this PR is ready for maintainer review |


What problem does this PR solve?
Issue Number: resolve
Problem Summary:
On macOS, repeated
futex_wake_private()calls can count an already notified waiteragain before it resumes. Callers such as
TaskControl::signal_task()may consequentlystop notifying other parking lots prematurely, leaving idle workers asleep while tasks
remain queued
What is changed and the side effects?
Changed:
owning a condition variable and notification flag.
from counting it again.
the original deadline.
Side effects:
Performance effects:
Breaking backward compatibility:
Check List: