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 Mutex#sleep race condition #2361

Merged
merged 3 commits into from
Dec 1, 2024
Merged

Fix Mutex#sleep race condition #2361

merged 3 commits into from
Dec 1, 2024

Conversation

seven1m
Copy link
Member

@seven1m seven1m commented Dec 1, 2024

Mutex#sleep acts like an atomic Mutex#unlock + Thread#sleep.

If some other thread sneaks in the middle of that and calls Thread#wakeup, the wakeup can be lost because we're not quite sleeping yet. m_wakeup is the "condition" for our std::condition_variable that allows us to check if we should immediately wake up.

Fixes #2340 and #1966.

This is a bit more accurate.
The thread can report it is still running even though it will be
sleeping very soon.
Mutex#sleep acts like an atomic Mutex#unlock + Thread#sleep.

If some other thread sneaks in the middle of that and calls
Thread#wakeup, the wakeup can be lost because we're not quite sleeping
yet. `m_wakeup` is the "condition" for our std::condition_variable that
allows us to check if we should immediately wake up.
@seven1m seven1m merged commit a1de4cc into master Dec 1, 2024
16 checks passed
@seven1m seven1m deleted the cond-var-sig-spec branch December 1, 2024 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timeout running condition variable signal_spec.rb
1 participant