Repository navigation
Conversation
…signal at a timeout, MRI's timeout errors The wait_spec failures in Util/sweep-core.tsv were stale (fixed by 4c5d542 and 4b0848c): spec/core/conditionvariable passes, 11 of 11. Comparing against MRI 4.0 turned up three problems the specs do not cover: - #wait on a mutex the thread does not hold raised ThreadError but left the thread queued as a waiter. The next #signal went to it: the real waiter slept through its timeout, and the failed caller kept a latched wake that cut its next sleep short. - #signal woke a waiter outside the waiter-list lock, so one whose timeout ran out at the same moment answered nil, the signal was lost, and the wake stayed latched. The wake is now sent under the lock, and a waiter that finds itself taken off the list counts as signalled and clears the latch. - #wait(mutex, timeout) took Queue#pop's conversion: a negative timeout returned at once and other types got "no implicit conversion". It now shares Mutex#sleep's conversion, which also learns MRI's RangeError for a Bignum, NaN and Infinity. Util/condvar-matrix.rb diffs these against CRuby. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 29, 2026
Closed
Owner
Author
|
Moved upstream: Largo#42. The branch stays. |
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.
The
wait_specfailures and thebroadcast_specNO-TALLY inUtil/sweep-core.tsvare stale. That sweep dates from 2026-09-12, and 4c5d542 and 4b0848c have fixed it since. On current master all ofspec/core/conditionvariablepasses (11/11), including 48 repeated runs at 8 in parallel.Comparing
#waitagainst MRI 4.0 turned up three bugs the specs don't cover. This PR fixes them:#waitstayed queued.cv.wait(m)on a mutex the thread doesn't hold raised ThreadError but left the thread queued as a waiter. The next#signalwent to that entry, so the real waiter slept through its whole timeout. The failed caller also kept a latched wake, so its nextm.sleep(0.01)returned right away with0instead ofnil.#signalremoved the waiter and woke it outside the lock. A waiter whose timeout expired at that moment returnednil, the signal was lost, and the AutoResetEvent stayed latched. The wake is now sent under the waiter-list lock. A waiter that finds it has been taken off the list counts as signalled: it returns the elapsed seconds and clears the latch.#wait's timeout was converted like Queue#pop's. A negative timeout returned at once, where MRI raisesArgumentError: time interval must not be negative, and the wrong TypeError message was used. MRI's#waitismutex.sleep(timeout), so it now usesMutex#sleep's conversion. That conversion also gains MRI's RangeError for a Bignum, NaN and Infinity.RubyQueue.csis unchanged.Util/condvar-matrix.rbchecks these cases against CRuby, and its output matches.Testing (Linux, net10.0)
> FAILEDThread#kill kills other fibers of that thread without running their ensure clauses. This one is a flake that predates the change. In 25 interleaved runs ofkill_spec.rbeach, the unmodified build failed it 6 times and this branch 2 times. It fails in every full-directory run on both builds. It uses neither Mutex nor ConditionVariable.Not fixed
Rationaltimeout raises TypeError in both#waitandMutex#sleep, where MRI accepts it. That was already the case before this PR, and IO.select behaves the same way.ConditionVariable/Mutex, where MRI printsThread::ConditionVariable. That's a constant-naming issue outside this PR.🤖 Generated with Claude Code