summaryrefslogtreecommitdiff
path: root/test/fiber/test_mutex.rb
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-09-11 20:47:25 +1200
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-09-14 16:44:09 +1200
commit0f613cc5f1bbe319ab916be905de263523ef5402 (patch)
tree84f707d136241822a547a222e40a98efb57aca49 /test/fiber/test_mutex.rb
parent1a0cfe28390ce5d46f7b854eaad2b9b979c160de (diff)
Add support for ConditionVariable.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3434
Diffstat (limited to 'test/fiber/test_mutex.rb')
-rw-r--r--test/fiber/test_mutex.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/fiber/test_mutex.rb b/test/fiber/test_mutex.rb
index 393a44fc2f..21034128a1 100644
--- a/test/fiber/test_mutex.rb
+++ b/test/fiber/test_mutex.rb
@@ -47,6 +47,43 @@ class TestFiberMutex < Test::Unit::TestCase
thread.join
end
+ def test_condition_variable
+ mutex = Mutex.new
+ condition = ConditionVariable.new
+
+ signalled = 0
+
+ thread = Thread.new do
+ scheduler = Scheduler.new
+ Thread.current.scheduler = scheduler
+
+ Fiber.schedule do
+ mutex.synchronize do
+ 3.times do
+ condition.wait(mutex)
+ signalled += 1
+ end
+ end
+ end
+
+ Fiber.schedule do
+ 3.times do
+ mutex.synchronize do
+ condition.signal
+ end
+
+ sleep 0.1
+ end
+ end
+
+ scheduler.run
+ end
+
+ thread.join
+
+ assert signalled > 1
+ end
+
def test_mutex_deadlock
err = /No live threads left. Deadlock\?/
assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['in synchronize'], err, success: false