[前][次][番号順一覧][スレッド一覧]

ruby-changes:14102

From: shyouhei <ko1@a...>
Date: Wed, 25 Nov 2009 16:45:42 +0900 (JST)
Subject: [ruby-changes:14102] Ruby:r25916 (ruby_1_8_7): merge revision(s) 25420:

shyouhei	2009-11-25 16:45:29 +0900 (Wed, 25 Nov 2009)

  New Revision: 25916

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25916

  Log:
    merge revision(s) 25420:
    * lib/monitor.rb (MonitorMixin.mon_release): ensure the scheduled
      thread to be alive when a thread is releasing a monitor. #2240

  Modified files:
    branches/ruby_1_8_7/ChangeLog
    branches/ruby_1_8_7/lib/monitor.rb
    branches/ruby_1_8_7/test/monitor/test_monitor.rb
    branches/ruby_1_8_7/version.h

Index: ruby_1_8_7/ChangeLog
===================================================================
--- ruby_1_8_7/ChangeLog	(revision 25915)
+++ ruby_1_8_7/ChangeLog	(revision 25916)
@@ -1,3 +1,8 @@
+Wed Nov 25 16:43:24 2009  NAKAMURA, Hiroshi  <nahi@r...>
+
+	* lib/monitor.rb (MonitorMixin.mon_release): ensure the scheduled
+	  thread to be alive when a thread is releasing a monitor. #2240
+
 Wed Nov 25 16:28:11 2009  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* lib/rexml/element.rb (text=): false should be converted to string.
Index: ruby_1_8_7/version.h
===================================================================
--- ruby_1_8_7/version.h	(revision 25915)
+++ ruby_1_8_7/version.h	(revision 25916)
@@ -2,7 +2,7 @@
 #define RUBY_RELEASE_DATE "2009-11-25"
 #define RUBY_VERSION_CODE 187
 #define RUBY_RELEASE_CODE 20091125
-#define RUBY_PATCHLEVEL 222
+#define RUBY_PATCHLEVEL 223
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8
Index: ruby_1_8_7/lib/monitor.rb
===================================================================
--- ruby_1_8_7/lib/monitor.rb	(revision 25915)
+++ ruby_1_8_7/lib/monitor.rb	(revision 25916)
@@ -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_7/test/monitor/test_monitor.rb
===================================================================
--- ruby_1_8_7/test/monitor/test_monitor.rb	(revision 25915)
+++ ruby_1_8_7/test/monitor/test_monitor.rb	(revision 25916)
@@ -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,10 @@
       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/

[前][次][番号順一覧][スレッド一覧]