aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_flip.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-09 05:32:33 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-09 05:32:33 +0000
commitf608b1b8dc3fd1ff9578e88c4ec3b55bf620f469 (patch)
treea156c72a5e4833724347378133393c45bb3405aa /test/ruby/test_flip.rb
parent193e1fc81055e99626f08a43a4fc7ccb96933091 (diff)
downloadruby-f608b1b8dc3fd1ff9578e88c4ec3b55bf620f469.tar.gz
test_flip.rb: flip-flop shared by threads
* test/ruby/test_flip.rb (TestFlip#test_shared_thread): flip-flop should be separated per threads git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_flip.rb')
-rw-r--r--test/ruby/test_flip.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_flip.rb b/test/ruby/test_flip.rb
index bd14228a8c..fc62d93ae6 100644
--- a/test/ruby/test_flip.rb
+++ b/test/ruby/test_flip.rb
@@ -18,4 +18,25 @@ class TestFlip < Test::Unit::TestCase
v = eval("vs.select {|n| if n==3..n==6 then 1 end}")
assert_equal([*3..6], v, bug7671)
end
+
+ def test_shared_thread
+ ff = proc {|n| true if n==3..n==5}
+ v = 1..9
+ a = true
+ th = Thread.new {
+ v.select {|i|
+ Thread.pass while a
+ ff[i].tap {a = true}
+ }
+ }
+ v1 = v.select {|i|
+ Thread.pass until a
+ ff[i].tap {a = false}
+ }
+ v2 = th.value
+ expected = [3, 4, 5]
+ mesg = 'flip-flop should be separated per threads'
+ assert_equal(expected, v1, mesg)
+ assert_equal(expected, v2, mesg)
+ end
end