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

ruby-changes:3629

From: ko1@a...
Date: Sat, 19 Jan 2008 03:48:33 +0900 (JST)
Subject: [ruby-changes:3629] matz - Ruby:r15118 (trunk): * thread.c (thread_create_core): prohibit thread creation in the

matz	2008-01-19 03:48:12 +0900 (Sat, 19 Jan 2008)

  New Revision: 15118

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_thread.rb
    trunk/thread.c

  Log:
    * thread.c (thread_create_core): prohibit thread creation in the
      frozen thread group.  a patch in [ruby-dev:33176] from sheepman
      <sheepman AT sheepman.sakura.ne.jp>.
    
    * thread.c (thread_create_core): should inherit ThreadGroup from
      the current thread.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15118&r2=15117&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/thread.c?r1=15118&r2=15117&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_thread.rb?r1=15118&r2=15117&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15117)
+++ ChangeLog	(revision 15118)
@@ -1,3 +1,12 @@
+Sat Jan 19 03:46:42 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* thread.c (thread_create_core): prohibit thread creation in the
+	  frozen thread group.  a patch in [ruby-dev:33176] from sheepman
+	  <sheepman AT sheepman.sakura.ne.jp>.
+
+	* thread.c (thread_create_core): should inherit ThreadGroup from
+	  the current thread.
+
 Sat Jan 19 00:37:19 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* sprintf.c (rb_str_format): set result encoding for wider width.
Index: thread.c
===================================================================
--- thread.c	(revision 15117)
+++ thread.c	(revision 15118)
@@ -374,6 +374,10 @@
 {
     rb_thread_t *th;
 
+    if (OBJ_FROZEN(GET_THREAD()->thgroup)) {
+	rb_raise(rb_eThreadError,
+		 "can't start a new thread (frozen ThreadGroup)");
+    }
     GetThreadPtr(thval, th);
 
     /* setup thread environment */
@@ -382,7 +386,7 @@
     th->first_func = fn;
 
     th->priority = GET_THREAD()->priority;
-    th->thgroup = th->vm->thgroup_default;
+    th->thgroup = GET_THREAD()->thgroup;
 
     native_mutex_initialize(&th->interrupt_lock);
     /* kick thread */
Index: test/ruby/test_thread.rb
===================================================================
--- test/ruby/test_thread.rb	(revision 15117)
+++ test/ruby/test_thread.rb	(revision 15118)
@@ -22,3 +22,36 @@
   end
 end
 
+class TestThreadGroup < Test::Unit::TestCase
+  def test_thread_init
+    thgrp = ThreadGroup.new
+    Thread.new{
+      thgrp.add(Thread.current)
+      assert_equal(thgrp, Thread.new{sleep 1}.group)
+    }.join
+  end
+
+  def test_frozen_thgroup
+    thgrp = ThreadGroup.new
+    Thread.new{
+      thgrp.add(Thread.current)
+      thgrp.freeze
+      assert_raise(ThreadError) do
+        Thread.new{1}.join
+      end
+    }.join
+  end
+
+  def test_enclosed_thgroup
+    thgrp = ThreadGroup.new
+    thgrp.enclose
+    Thread.new{
+      assert_raise(ThreadError) do
+        thgrp.add(Thread.current)
+      end
+      assert_nothing_raised do
+        Thread.new{1}.join
+      end
+    }.join
+  end
+end

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

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