mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Revert r64441
* This reverts commit 647fc1227a
:
"thread_sync.c (rb_mutex_synchronize): only unlock if we own the mutex"
* Let's try to preserve the semantics of always being locked inside
Mutex#synchronize, even if an exception interrupts ConditionVariable#wait.
* As discussed on [Bug #14999].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b5b5b28c65
commit
c742050ea5
2 changed files with 44 additions and 56 deletions
|
@ -23,15 +23,21 @@ describe "ConditionVariable#wait" do
|
|||
th.join
|
||||
end
|
||||
|
||||
it "the lock remains usable even if the thread is killed" do
|
||||
it "reacquires the lock even if the thread is killed" do
|
||||
m = Mutex.new
|
||||
cv = ConditionVariable.new
|
||||
in_synchronize = false
|
||||
owned = nil
|
||||
|
||||
th = Thread.new do
|
||||
m.synchronize do
|
||||
in_synchronize = true
|
||||
cv.wait(m)
|
||||
begin
|
||||
cv.wait(m)
|
||||
ensure
|
||||
owned = m.owned?
|
||||
$stderr.puts "\nThe Thread doesn't own the Mutex!" unless owned
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,19 +49,24 @@ describe "ConditionVariable#wait" do
|
|||
th.kill
|
||||
th.join
|
||||
|
||||
m.try_lock.should == true
|
||||
m.unlock
|
||||
owned.should == true
|
||||
end
|
||||
|
||||
it "lock remains usable even if the thread is killed after being signaled" do
|
||||
it "reacquires the lock even if the thread is killed after being signaled" do
|
||||
m = Mutex.new
|
||||
cv = ConditionVariable.new
|
||||
in_synchronize = false
|
||||
owned = nil
|
||||
|
||||
th = Thread.new do
|
||||
m.synchronize do
|
||||
in_synchronize = true
|
||||
cv.wait(m)
|
||||
begin
|
||||
cv.wait(m)
|
||||
ensure
|
||||
owned = m.owned?
|
||||
$stderr.puts "\nThe Thread doesn't own the Mutex!" unless owned
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,8 +84,7 @@ describe "ConditionVariable#wait" do
|
|||
}
|
||||
|
||||
th.join
|
||||
m.try_lock.should == true
|
||||
m.unlock
|
||||
owned.should == true
|
||||
end
|
||||
|
||||
it "supports multiple Threads waiting on the same ConditionVariable and Mutex" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue