ruby-changes:39787
From: kosaki <ko1@a...>
Date: Wed, 16 Sep 2015 04:24:05 +0900 (JST)
Subject: [ruby-changes:39787] kosaki:r51868 (trunk): * test/ruby/test_thread.rb (TestThread#test_mutex_synchronize):
kosaki 2015-09-16 04:23:43 +0900 (Wed, 16 Sep 2015) New Revision: 51868 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51868 Log: * test/ruby/test_thread.rb (TestThread#test_mutex_synchronize): insert waste loop for invoking preemptive thread context switch. Modified files: trunk/ChangeLog trunk/test/ruby/test_thread.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 51867) +++ ChangeLog (revision 51868) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Sep 16 03:49:19 2015 KOSAKI Motohiro <kosaki.motohiro@g...> + + * test/ruby/test_thread.rb (TestThread#test_mutex_synchronize): + insert waste loop for invoking preemptive thread context switch. + [Bug #11496] + Tue Sep 15 19:38:55 2015 Nobuyoshi Nakada <nobu@r...> * gc.c (rb_objspace_alloc, rb_objspace_free): define always Index: test/ruby/test_thread.rb =================================================================== --- test/ruby/test_thread.rb (revision 51867) +++ test/ruby/test_thread.rb (revision 51868) @@ -97,21 +97,24 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L97 def test_mutex_synchronize m = Mutex.new r = 0 - max = 10 - (1..max).map{ + num_threads = 10 + loop=100 + (1..num_threads).map{ Thread.new{ - i=0 - while i<max*max - i+=1 + loop.times{ m.synchronize{ - r += 1 + tmp = r + # empty and waste loop for making thread preemption + 100.times { + } + r = tmp + 1 } - end + } } }.each{|e| e.join } - assert_equal(max * max * max, r) + assert_equal(num_threads*loop, r) end def test_mutex_synchronize_yields_no_block_params -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/