summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-09-20 13:29:24 +0200
committerBenoit Daloze <eregontp@gmail.com>2020-09-20 13:35:39 +0200
commit6987c8997e6cd8f45bbd7ece6582c0024be0cc0f (patch)
treee4c29386daeb1e4179c8b5f180782cd511898b65 /test
parent73a626c0789161911aa5753859c4a81ed2dfd999 (diff)
Remove from waiter in Mutex#lock with ensure when calling rb_scheduler_block()
* Previously this could lead to an invalid waiter entry and then trying to wake up that waiter would result in various issues in rb_mutex_unlock_th().
Diffstat (limited to 'test')
-rw-r--r--test/fiber/test_mutex.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/fiber/test_mutex.rb b/test/fiber/test_mutex.rb
index a70c6992ab..258f5358a6 100644
--- a/test/fiber/test_mutex.rb
+++ b/test/fiber/test_mutex.rb
@@ -70,6 +70,38 @@ class TestFiberMutex < Test::Unit::TestCase
thread.join
end
+ def test_mutex_fiber_raise
+ mutex = Mutex.new
+ ran = false
+
+ main = Thread.new do
+ mutex.lock
+
+ thread = Thread.new do
+ scheduler = Scheduler.new
+ Thread.current.scheduler = scheduler
+
+ f = Fiber.schedule do
+ assert_raise_with_message(RuntimeError, "bye") do
+ assert_same scheduler, Thread.scheduler
+ mutex.lock
+ end
+ ran = true
+ end
+
+ Fiber.schedule do
+ f.raise "bye"
+ end
+ end
+
+ thread.join
+ end
+
+ main.join # causes mutex to be released
+ assert_equal false, mutex.locked?
+ assert_equal true, ran
+ end
+
def test_condition_variable
mutex = Mutex.new
condition = ConditionVariable.new