Issue #11178 has been reported by Cyril Vechera.

----------------------------------------
Bug #11178: possible bug: a thread killed when waiting on ConditionVariable locks the mutex again before real exit
https://bugs.ruby-lang.org/issues/11178

* Author: Cyril Vechera
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Probably it's not a bug, but just a hidden behaviour. Please write your comments.

When a thread waits on ConditionVariable, it releases the mutex. And killing the thread during this state assumes no need to lock the mutex again because there's no ruby code to be executed. It results to problems:
* the killed thread remains alive until the mutex is released by another thread
* joining the killed thread from another thread locked on the mutex brings to deadlock

~~~
@m= Mutex.new
@r = ConditionVariable.new

t = Thread.new {
	@m.synchronize do
		@r.wait(@m)
	end
}

sleep 0.01

@m.synchronize do
	t.kill
	sleep 0.01
	puts "alive?: #{t.alive?}" # the thread should not be alive here
	t.join # at this point we're getting dealock
end

~~~


---Files--------------------------------
1.rb (240 Bytes)


-- 
https://bugs.ruby-lang.org/