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
merged 8 commits into from Apr 10, 2019

Conversation

@headius
Copy link
Member

commented Apr 9, 2019

Fixes #5476.

@headius headius added this to the JRuby 9.2.8.0 milestone Apr 9, 2019

headius added some commits Apr 9, 2019

Return to interruptible lock acquisition in Mutex.
Fixes #5476.

This reverts the original change from #4261 that disabled lock
interrupts, and uses Task logic from RubyThread to handle the
interrupting properly.
Centralize some threading logic for Mutex, CondVar.
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 #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.

@headius headius force-pushed the headius:java_interruptible_mutex branch from d6146cb to ed97131 Apr 10, 2019

headius added some commits Apr 10, 2019

Tidy up ConditionVariable.
* Move remaining non-waiter logic to a sleep dyncall, as in MRI.
* Restore deprecated wait_ruby with [] args.
Final tweaks to ConditionVariable.
* Arity split #wait all the way through to avoid nil coercion
  error in arity-split Mutex#sleep.
* Remove waiters while interrupting in #broadcast.
Bit more cleanup for CRuby tests.
* Properly unify Mutex#sleep arities to match CRuby behavior.
* Unify ConditionVariable#wait_ruby logic again.
@headius

This comment has been minimized.

Copy link
Member Author

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

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
jruby.jruby Build #20190410.5 succeeded
Details

@headius headius deleted the headius:java_interruptible_mutex branch Apr 10, 2019

@kares

This comment has been minimized.

Copy link
Member

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
Projects
None yet
2 participants
You can’t perform that action at this time.