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

ruby-changes:18669

From: yugui <ko1@a...>
Date: Fri, 28 Jan 2011 11:26:25 +0900 (JST)
Subject: [ruby-changes:18669] Ruby:r30693 (ruby_1_9_2): merges r30647,r30650 and r30651 from trunk into ruby_1_9_2.

yugui	2011-01-28 11:25:38 +0900 (Fri, 28 Jan 2011)

  New Revision: 30693

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

  Log:
    merges r30647,r30650 and r30651 from trunk into ruby_1_9_2.
    --
    * test/ruby/test_thread.rb: Added various ConditionVariable tests.
    --
    * test/ruby/test_thread.rb (TestThread#test_condvar_nolock_2): get rid of method redefined.
    --
    * test/ruby/test_thread.rb: remove unused variables.

  Modified files:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/test/ruby/test_thread.rb
    branches/ruby_1_9_2/version.h

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 30692)
+++ ruby_1_9_2/ChangeLog	(revision 30693)
@@ -1,3 +1,16 @@
+Tue Jan 25 07:48:22 2011  Kazuhiro NISHIYAMA  <zn@m...>
+
+	* test/ruby/test_thread.rb: remove unused variables.
+
+Tue Jan 25 07:45:44 2011  Kazuhiro NISHIYAMA  <zn@m...>
+
+	* test/ruby/test_thread.rb (TestThread#test_condvar_nolock_2): get
+	  rid of method redefined.
+
+Tue Jan 25 03:24:28 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* test/ruby/test_thread.rb: Added various ConditionVariable tests.
+
 Mon Jan 24 21:04:45 2011  Nobuyoshi Nakada  <nobu@r...>
 
 	* error.c (rb_invalid_str): prevent intermediate variable from GC.
Index: ruby_1_9_2/version.h
===================================================================
--- ruby_1_9_2/version.h	(revision 30692)
+++ ruby_1_9_2/version.h	(revision 30693)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_PATCHLEVEL 170
+#define RUBY_PATCHLEVEL 171
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
Index: ruby_1_9_2/test/ruby/test_thread.rb
===================================================================
--- ruby_1_9_2/test/ruby/test_thread.rb	(revision 30692)
+++ ruby_1_9_2/test/ruby/test_thread.rb	(revision 30693)
@@ -102,6 +102,119 @@
     assert(locked)
   end
 
+  def test_condvar_wait_and_broadcast
+    nr_threads = 3
+    threads = Array.new
+    mutex = Mutex.new
+    condvar = ConditionVariable.new
+    result = []
+
+    nr_threads.times do |i|
+      threads[i] = Thread.new do
+        mutex.synchronize do
+          result << "C1"
+          condvar.wait mutex
+          result << "C2"
+        end
+      end
+    end
+    sleep 0.1
+    mutex.synchronize do
+      result << "P1"
+      condvar.broadcast
+      result << "P2"
+    end
+    nr_threads.times do |i|
+      threads[i].join
+    end
+
+    assert_equal ["C1", "C1", "C1", "P1", "P2", "C2", "C2", "C2"], result
+  end
+
+#  Hmm.. don't we have a way of catch fatal exception?
+#
+#  def test_cv_wait_deadlock
+#    mutex = Mutex.new
+#    cv = ConditionVariable.new
+#
+#    assert_raises(fatal) {
+#      mutex.lock
+#      cv.wait mutex
+#      mutex.unlock
+#    }
+#  end
+
+  def test_condvar_wait_deadlock_2
+    nr_threads = 3
+    threads = Array.new
+    mutex = Mutex.new
+    condvar = ConditionVariable.new
+
+    nr_threads.times do |i|
+      if (i != 0)
+        mutex.unlock
+      end
+      threads[i] = Thread.new do
+        mutex.synchronize do
+          condvar.wait mutex
+        end
+      end
+      mutex.lock
+    end
+
+    assert_raise(Timeout::Error) do
+      Timeout.timeout(0.1) { condvar.wait mutex }
+    end
+    mutex.unlock rescue
+    threads[i].each.join
+  end
+
+  def test_condvar_timed_wait
+    mutex = Mutex.new
+    condvar = ConditionVariable.new
+    timeout = 0.3
+    locked = false
+
+    t0 = Time.now
+    mutex.synchronize do
+      begin
+        condvar.wait(mutex, timeout)
+      ensure
+        locked = mutex.locked?
+      end
+    end
+    t1 = Time.now
+    t = t1-t0
+
+    assert_block { timeout*0.9 < t && t < timeout*1.1 }
+    assert(locked)
+  end
+
+  def test_condvar_nolock
+    mutex = Mutex.new
+    condvar = ConditionVariable.new
+
+    assert_raise(ThreadError) { condvar.wait(mutex) }
+  end
+
+  def test_condvar_nolock_2
+    mutex = Mutex.new
+    condvar = ConditionVariable.new
+
+    Thread.new do
+      assert_raise(ThreadError) {condvar.wait(mutex)}
+    end.join
+  end
+
+  def test_condvar_nolock_3
+    mutex = Mutex.new
+    condvar = ConditionVariable.new
+
+    Thread.new do
+      assert_raise(ThreadError) {condvar.wait(mutex, 0.1)}
+    end.join
+  end
+
   def test_local_barrier
     dir = File.dirname(__FILE__)
     lbtest = File.join(dir, "lbtest.rb")

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

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