Repository navigation
Wake the killed thread, not another waiter, on a monitor wait - #9847
Open
sampokuokkanen wants to merge 1 commit into
Open
sampokuokkanen wants to merge 1 commit into
sampokuokkanen wants to merge 1 commit into
Conversation
waitForObject waits with Object.wait, and a kill or raise woke it with notify, which wakes one arbitrary waiter on that monitor. When two threads waited on the same object, the other one could wake instead, see nothing pending, and wait again, leaving the killed thread blocked. concurrent-ruby waits this way, which made its CyclicBarrier spec time out joining killed threads now and then. Use notifyAll. Monitor waiters have to recheck their condition anyway.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
waitForObject waits with Object.wait, and a kill or raise woke it with notify, which wakes one arbitrary waiter on that monitor. When two threads waited on the same object, the other one could wake instead, see nothing pending, and wait again, leaving the killed thread blocked. concurrent-ruby waits this way, which made its CyclicBarrier spec time out joining killed threads now and then.
notify() could wake some other waiter instead of the killed thread. notifyAll() wakes them all; the rest just recheck and go back to waiting.
Should fix the occasional CI error
Concurrent::CyclicBarrier#number_waiting with waiting threads should be equal to the waiting threads countlike here: https://github.com/jruby/jruby/actions/runs/39355604931/job/118409545094?pr=9845.Related to ruby-concurrency/concurrent-ruby#862.