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

Return to interruptible lock acquisition in Mutex. #5683

merged 8 commits into from
Apr 10, 2019


Copy link

@headius headius commented Apr 9, 2019

Fixes #5476.

@headius headius added this to the JRuby milestone Apr 9, 2019
Fixes jruby#5476.

This reverts the original change from jruby#4261 that disabled lock
interrupts, and uses Task logic from RubyThread to handle the
interrupting properly.
This better models the way MRI uses the Mutex. Rather than
directly doing the unlock, sleep, lock steps, this version just
adds the thread to a listeners queue and asks the mutex to sleep.
This allows us to reuse the sleep logic already in Mutex, which
now properly defers to RubyThread methods to do its own unlock,
sleep, lock cycle. This centralizes all of the key Mutex behaviors
in RubyThread so they can be properly boxed with thread status
changes like "sleep".

This also fixes jruby#5476 by restoring full interruptibility to Mutex
contended lock calls. Both interrupts from Java and from Ruby will
wake the thread. This returns us to matching MRI's Mutex lock
interrupt behavior.
* Move remaining non-waiter logic to a sleep dyncall, as in MRI.
* Restore deprecated wait_ruby with [] args.
* Arity split #wait all the way through to avoid nil coercion
  error in arity-split Mutex#sleep.
* Remove waiters while interrupting in #broadcast.
* Properly unify Mutex#sleep arities to match CRuby behavior.
* Unify ConditionVariable#wait_ruby logic again.
Copy link
Member Author

headius commented Apr 10, 2019

Going ahead with this since it's nice and green, mostly deletes code, and matches CRuby behavior much more closely now.

@headius headius merged commit 7c9fa26 into jruby:master Apr 10, 2019
@headius headius deleted the java_interruptible_mutex branch April 10, 2019 21:39
Copy link

kares commented Apr 11, 2019

very nice work, indeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants