ruby-changes:16264
From: wyhaines <ko1@a...>
Date: Wed, 9 Jun 2010 01:35:23 +0900 (JST)
Subject: [ruby-changes:16264] Ruby:r28232 (ruby_1_8_6): lib/monitor.rb: Backport #2240 ; backport r25420 to ensure that the scheduled thread is alive when a monitor is released.
wyhaines 2010-06-09 01:35:10 +0900 (Wed, 09 Jun 2010) New Revision: 28232 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28232 Log: lib/monitor.rb: Backport #2240 [ruby-core:26185]; backport r25420 to ensure that the scheduled thread is alive when a monitor is released. test/monitor/test_monitor.rb: Backport #2240 [ruby-core:26185]; added a test for the above functionality. Modified files: branches/ruby_1_8_6/ChangeLog branches/ruby_1_8_6/lib/monitor.rb branches/ruby_1_8_6/test/monitor/test_monitor.rb branches/ruby_1_8_6/version.h Index: ruby_1_8_6/ChangeLog =================================================================== --- ruby_1_8_6/ChangeLog (revision 28231) +++ ruby_1_8_6/ChangeLog (revision 28232) @@ -1,8 +1,14 @@ +Wed June 9 01:05:00 Kirk Haines <khaines@r...> + + * lib/monitor.rb: Backport #2240 [ruby-core:26185]; backport r25420 to ensure that the scheduled thread is alive when a monitor is released. + * test/monitor/test_monitor.rb: Backport #2240 [ruby-core:26185]; added a test for the above functionality. + + Tue Jun 8 23:45:00 2010 Kirk Haines <khaines@r...> - * regexp.c: Backport #3403; backported from r28192 to fix a bug with non-greedy matching. - * test/ruby/test_regexp.rb: Backport #3403; added this test suite, commenting out inapplicable tests to the current 1.8.6. - * ChangeLog: Got my date wrong in the last few entries. Tuesday is the 8th, not the 9th! + * regexp.c: Backport #3403; backported from r28192 to fix a bug with non-greedy matching. r28231 + * test/ruby/test_regexp.rb: Backport #3403; added this test suite, commenting out inapplicable tests to the current 1.8.6. r28231 + * ChangeLog: Got my date wrong in the last few entries. Tuesday is the 8th, not the 9th! r28231 Tue Jun 8 20:40:00 2010 Kirk Haines <khaines@r...> Index: ruby_1_8_6/version.h =================================================================== --- ruby_1_8_6/version.h (revision 28231) +++ ruby_1_8_6/version.h (revision 28232) @@ -1,15 +1,15 @@ #define RUBY_VERSION "1.8.6" -#define RUBY_RELEASE_DATE "2010-06-08" +#define RUBY_RELEASE_DATE "2010-06-09" #define RUBY_VERSION_CODE 186 -#define RUBY_RELEASE_CODE 20100608 -#define RUBY_PATCHLEVEL 407 +#define RUBY_RELEASE_CODE 20100609 +#define RUBY_PATCHLEVEL 408 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8 #define RUBY_VERSION_TEENY 6 #define RUBY_RELEASE_YEAR 2010 #define RUBY_RELEASE_MONTH 6 -#define RUBY_RELEASE_DAY 8 +#define RUBY_RELEASE_DAY 9 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; Index: ruby_1_8_6/lib/monitor.rb =================================================================== --- ruby_1_8_6/lib/monitor.rb (revision 28231) +++ ruby_1_8_6/lib/monitor.rb (revision 28232) @@ -288,11 +288,15 @@ @mon_owner = Thread.current end + # mon_release requires Thread.critical == true def mon_release @mon_owner = nil - t = @mon_waiting_queue.shift - t = @mon_entering_queue.shift unless t - t.wakeup if t + while t = @mon_waiting_queue.shift || @mon_entering_queue.shift + if t.alive? + t.wakeup + return + end + end end def mon_enter_for_cond(count) Index: ruby_1_8_6/test/monitor/test_monitor.rb =================================================================== --- ruby_1_8_6/test/monitor/test_monitor.rb (revision 28231) +++ ruby_1_8_6/test/monitor/test_monitor.rb (revision 28232) @@ -54,6 +54,32 @@ assert_equal((1..10).to_a, ary) end + def test_killed_thread_in_synchronize + ary = [] + queue = Queue.new + t1 = Thread.start { + queue.pop + @monitor.synchronize { + ary << :t1 + } + } + t2 = Thread.start { + queue.pop + @monitor.synchronize { + ary << :t2 + } + } + @monitor.synchronize do + queue.enq(nil) + queue.enq(nil) + assert_equal([], ary) + t1.kill + t2.kill + ary << :main + end + assert_equal([:main], ary) + end + def test_try_enter queue1 = Queue.new queue2 = Queue.new @@ -94,7 +120,11 @@ assert_equal(true, result1) assert_equal("bar", a) end + end + def test_timedwait + cond = @monitor.new_cond + b = "foo" queue2 = Queue.new Thread.start do -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/