Skip to content

Commit 0cb6ddb

Browse files
committed
Narrow deadlock check for fibers and fix message
* Only raise deadlock error when two different fibers from the same thread attempt to lock (jruby#9218). * Store the real parent thread as the locking thread for deadlock checks (fixes second case added in spec). Fixes jruby#9218
1 parent 4db0c8a commit 0cb6ddb

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

core/src/main/java/org/jruby/ext/thread/Mutex.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public IRubyObject lock(ThreadContext context) {
106106

107107
checkRelocking(context);
108108

109-
if (this.lockingThread == parentThread) {
109+
RubyThread lockingThread = this.lockingThread;
110+
if (lockingThread == parentThread && context.getFiber() != lockingThread.getContext().getFiber()) {
110111
throw context.runtime.newThreadError("deadlock; lock already owned by another fiber belonging to the same thread");
111112
}
112113

@@ -123,7 +124,7 @@ public IRubyObject lock(ThreadContext context) {
123124
}
124125
}
125126

126-
this.lockingThread = thread;
127+
this.lockingThread = parentThread;
127128

128129
// always check for thread interrupts after acquiring lock
129130
try {
@@ -204,7 +205,7 @@ public IRubyObject owned_p(ThreadContext context) {
204205

205206
private void checkRelocking(ThreadContext context) {
206207
if (lock.isHeldByCurrentThread()) {
207-
throw context.runtime.newThreadError("Mutex relocking by same thread");
208+
throw context.runtime.newThreadError("deadlock; recursive locking");
208209
}
209210
}
210211

0 commit comments

Comments
 (0)