You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix late condition variable notifications after timeout - #8163
Review was skipped as selected files did not have any reviewable changes.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 5a3afaaf-7602-409b-8e5d-824098372c25
Commits
Reviewing files that changed from the base of the PR and between 89219dd and f92678e.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Bug Fixes
Improved reliability of timed waits when a notification arrives near the deadline. A wait now reports either a notification or a timeout, depending on which occurs first. Notifications that arrive after a waiter has left its wait no longer cause an unintended wakeup during a subsequent suspension.
Tests
Added repeated checks for notification races near timed-wait deadlines and for unintended wakeups during a subsequent suspension.
The condition-variable notifier now transitions the specific observed suspended thread state to pending with a signaled restart state. The unit test adds timed notification races for notify_one and notify_all and checks for unexpected wakeups during a later suspension.
Changes: Condition variable late-wakeup handling
Layer / File(s)
Summary
Resume the observed suspension libs/core/synchronization/src/detail/condition_variable.cpp
resume_waiter records the observed suspended thread state and uses it to transition that suspension to pending with a signaled restart state. It returns if the waiter has left its wait or no suspended state was captured.
Test timed notification races libs/core/synchronization/tests/unit/condition_variable_late_wakeup.cpp
The test races timed waits with notify_one and notify_all using a 2 ms deadline. It accepts signaled or timeout, then checks for unexpected wakeups during a subsequent suspension. Both timed variants run 100 times.
TheHPXProject/hpx#7904: Changes the same condition-variable late-wakeup behavior and notify path.
TheHPXProject/hpx#8108: Adds the tagged-state timer transition used by this PR for condition-variable notifications.
TheHPXProject/hpx#7879: Changes the condition-variable wait queue and notify path involved in late wakeups.
Suggested labels:type: defect
Merge Risk: Minimal · previous review 89219
This change stops a late condition-variable notification from waking a waiter's later, unrelated suspension after a timeout. No concrete defect was found in the new notifier logic, and the extended race test covers both notify_one and notify_all. The merge risk is minimal.
Pre-merge checks: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Linked Issues check
Issue #7916 has two coding requirements. (1) Notification side: resume a waiter only from the exact suspension observed, and never hand the wakeup to another thread. The diff in condition_variable.cpp…
Show that the timer wakeup for a timed suspension uses the same exact-suspension check at the reviewed base or head. The check must cover the case where a notification wakes the waiter and the waiter suspends again before its timer is cance…
Passed checks: 3 passed
Check name
Status
Explanation
Title check
The title "Fix late condition variable notifications after timeout" matches the main change: the PR stops a notification from waking a condition-variable waiter's later suspension when a timeout races…
Description check
The description states the fix (wake a waiter only if its tagged thread state still matches the observed suspension), reuses the suspension-aware transition from #8108, and extends the late-wakeup reg…
Out of Scope Changes check
All changed code lies within the scope of #7916. The condition_variable.cpp change replaces the suspended-flag logic in resume_waiter with suspended-state capture and set_suspended_thread_state. The t…
Full details: Title check
Explanation
The title "Fix late condition variable notifications after timeout" matches the main change: the PR stops a notification from waking a condition-variable waiter's later suspension when a timeout races the notification. The raw summary shows the resume_waiter change in condition_variable.cpp and a late-wakeup regression test, both consistent with the title.
Full details: Description check
Explanation
The description states the fix (wake a waiter only if its tagged thread state still matches the observed suspension), reuses the suspension-aware transition from #8108, and extends the late-wakeup regression test to notify_one and notify_all. It also lists build and test validation. This matches the changeset described in the raw summary.
Full details: Out of Scope Changes check
Explanation
All changed code lies within the scope of #7916. The condition_variable.cpp change replaces the suspended-flag logic in resume_waiter with suspended-state capture and set_suspended_thread_state. The test change adds test_timed_round, which covers the timed-wait notification race described in the issue. The copyright lines added to two files are administrative and do not change behavior. No unrelated behavior change appears in the reviewed diff.
Full details: Linked Issues check
Explanation
Issue #7916 has two coding requirements. (1) Notification side: resume a waiter only from the exact suspension observed, and never hand the wakeup to another thread. The diff in condition_variable.cpp addresses this. resume_waiter now stores the observed suspended thread_state, including its tag. It then calls threads::detail::set_suspended_thread_state(id, tag, pending, signaled, priority) and returns. It no longer calls ctx.resume(), so the set_thread_state/reschedule_active path is not used for this case. The reviewed diff does not show the internal failure behavior of set_suspended_thread_state. The requirement is met as far as the diff shows. (2) Timer side: the issue states that a timed suspension's timer can wake a later suspension after a notification has already woken the waiter. The PR description says the existing transition from #8108 covers timed wakes. The PR diff does not change the timer path, and the PR objectives state that it does not validate the timer-side race. The base-side implementation of the timer path was not inspected, so the timer-side requirement cannot be confirmed as met. The added test test_timed_round races notify_one and notify_all against a timed wait and counts stray wakeups. Its comment states that it is not a deterministic reproducer of #7916, so it gives only probabilistic coverage.
Resolution
Show that the timer wakeup for a timed suspension uses the same exact-suspension check at the reviewed base or head. The check must cover the case where a notification wakes the waiter and the waiter suspends again before its timer is cancelled. Name the file and function that implement this. Alternatively, add a change or a test that covers this timer-side case.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Fix failing CI checks
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer TIP This summary will be updated as you push new changes.
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is the fix #7916 asked for: the notifier now changes the waiter's state only from the exact suspension it observed (state and tag, through set_suspended_thread_state from #8108), and never hands the wakeup to another thread, so a timeout that ends the suspension in between turns the notification into a no-op.
One question: does the new test_timed_round fail on master? The window needs the timer to fire between reading the state and the wakeup, and the reproducer in #7916 only hit it with a sleep injected into resume_waiter. If it doesn't, that's fine, but please say in the test's comment that it exercises the path rather than reproducing the race. LGTM otherwise.
The current cross-platform build failures are in serialization code from master, before the condition-variable test builds. Master changed extra_data_id_type to std::size_t, while post_receive_actions::id() and preprocess_keep_alive::id() still return addresses; Linux, Windows, and CodeQL all report the same pointer-to-integer conversion error. This PR does not change those files.
I opened #8188 with the two-line ID fix as a separate PR. Its affected serialization target builds and the focused test passes locally. Once #8188 lands, this PR's CI can be rerun against the corrected master. Separately, as requested in the review, I verified that test_timed_round passed ten runs against the unfixed condition-variable implementation and documented in the test that it exercises the path without deterministically reproducing #7916.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7916.
Proposed changes
notify_oneandnotify_all.Validation
condition_variable_testandcondition_variable_late_wakeup_testwith AppleClang 21 in Release mode.--hpx:queuing=local-workrequesting-fifo.clang-format --dry-run --Werrorandgit diff --checkpassed.