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

ruby-changes:20444

From: kosaki <ko1@a...>
Date: Sun, 10 Jul 2011 16:46:11 +0900 (JST)
Subject: [ruby-changes:20444] kosaki:r32492 (trunk): * vm_core.h (typedef struct rb_vm_struct): create a new

kosaki	2011-07-10 16:46:00 +0900 (Sun, 10 Jul 2011)

  New Revision: 32492

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

  Log:
    * vm_core.h (typedef struct rb_vm_struct): create a new
      'inhibit_thread_createion' field.
    * thread.c (rb_thread_terminate_all): set inhibit_thread_creation.
    * thread.c (thread_s_new): don't permit to create new thread
      if the VM is under destruction. Otherwise evil finalizer code
      can make SEGV. [Bug #4992][ruby-core:37858]
    
    * bootstraptest/test_objectspace.rb: new test for this fix.

  Modified files:
    trunk/ChangeLog
    trunk/bootstraptest/test_objectspace.rb
    trunk/thread.c
    trunk/vm_core.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32491)
+++ ChangeLog	(revision 32492)
@@ -1,3 +1,14 @@
+Sun Jul 10 16:41:32 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* vm_core.h (typedef struct rb_vm_struct): create a new
+	  'inhibit_thread_createion' field.
+	* thread.c (rb_thread_terminate_all): set inhibit_thread_creation.
+	* thread.c (thread_s_new): don't permit to create new thread
+	  if the VM is under destruction. Otherwise evil finalizer code
+	  can make SEGV. [Bug #4992][ruby-core:37858]
+
+	* bootstraptest/test_objectspace.rb: new test for this fix.
+
 Sun Jul 10 16:06:16 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* signal.c (sigsegv): use abort() instead of exit() when nested
Index: bootstraptest/test_objectspace.rb
===================================================================
--- bootstraptest/test_objectspace.rb	(revision 32491)
+++ bootstraptest/test_objectspace.rb	(revision 32492)
@@ -38,3 +38,9 @@
     Mutex.new.lock
   end
 }, '[ruby-dev:44049]'
+
+assert_normal_exit %q{
+  ObjectSpace.define_finalizer("") do
+    Thread.new {}
+  end
+}, '[ruby-core:37858]'
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 32491)
+++ vm_core.h	(revision 32492)
@@ -285,6 +285,7 @@
     VALUE thgroup_default;
 
     int running;
+    int inhibit_thread_creation;
     int thread_abort_on_exception;
     unsigned long trace_flag;
     volatile int sleeper;
Index: thread.c
===================================================================
--- thread.c	(revision 32491)
+++ thread.c	(revision 32492)
@@ -367,6 +367,7 @@
 
     thread_debug("rb_thread_terminate_all (main thread: %p)\n", (void *)th);
     st_foreach(vm->living_threads, terminate_i, (st_data_t)th);
+    vm->inhibit_thread_creation = 1;
 
     while (!rb_thread_alone()) {
 	PUSH_TAG();
@@ -583,6 +584,10 @@
 {
     rb_thread_t *th;
     VALUE thread = rb_thread_alloc(klass);
+
+    if (GET_VM()->inhibit_thread_creation)
+	rb_raise(rb_eThreadError, "can't alloc thread");
+
     rb_obj_call_init(thread, argc, argv);
     GetThreadPtr(thread, th);
     if (!th->first_args) {

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

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