Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -1945,8 +1945,9 @@ public Long run(ThreadContext context, Object data) throws InterruptedException

@Override
public void wakeup(RubyThread thread, Object data) {
// notify could wake another thread waiting on the same object instead of this one, so wake them all
synchronized (data) {
data.notify();
data.notifyAll();
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions test/jruby/test_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,23 @@ def test_count_down_latch
end
end

# Extensions like concurrent-ruby wait on a Java monitor through RubyThread#waitForObject.
# Killing one of several waiters on the same monitor has to wake that one, not another.
def test_kill_wakes_the_killed_monitor_waiter
require 'jruby'

20.times do
lock = java.lang.Object.new
threads = 2.times.map do
Thread.new { JRuby.reference(Thread.current).waitForObject(lock, 0.0) }
end
Thread.pass until threads.all? { |t| t.status == 'sleep' }

threads.reverse_each do |t|
t.kill
assert t.join(5), "killed thread still waiting: #{t.inspect}"
end
end
end

end
Loading