ruby-changes:26696
From: nobu <ko1@a...>
Date: Wed, 9 Jan 2013 14:32:43 +0900 (JST)
Subject: [ruby-changes:26696] nobu:r38747 (trunk): test_flip.rb: flip-flop shared by threads
nobu 2013-01-09 14:32:33 +0900 (Wed, 09 Jan 2013) New Revision: 38747 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38747 Log: test_flip.rb: flip-flop shared by threads * test/ruby/test_flip.rb (TestFlip#test_shared_thread): flip-flop should be separated per threads Modified files: trunk/test/ruby/test_flip.rb Index: test/ruby/test_flip.rb =================================================================== --- test/ruby/test_flip.rb (revision 38746) +++ test/ruby/test_flip.rb (revision 38747) @@ -18,4 +18,25 @@ class TestFlip < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_flip.rb#L18 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/