Skip to content

Return to interruptible lock acquisition in Mutex.#5683

Merged
headius merged 8 commits intojruby:masterfrom
headius:java_interruptible_mutex
Apr 10, 2019
Merged

Return to interruptible lock acquisition in Mutex.#5683
headius merged 8 commits intojruby:masterfrom
headius:java_interruptible_mutex

Conversation

@headius
Copy link
Member

@headius headius commented Apr 9, 2019

Fixes #5476.

@headius headius added this to the JRuby 9.2.8.0 milestone Apr 9, 2019
headius added 3 commits April 9, 2019 14:46
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.
@headius headius force-pushed the java_interruptible_mutex branch from d6146cb to ed97131 Compare April 10, 2019 04:19
headius added 5 commits April 9, 2019 23:55
* 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.
@headius
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
@kares
Copy link
Member

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants