From a119b9d146fea877acc1e9ba5df0702163ce917a Mon Sep 17 00:00:00 2001 From: kosaki Date: Sun, 10 Jul 2011 07:46:00 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'thread.c') diff --git a/thread.c b/thread.c index cd5b49b868..ac72d5d038 100644 --- a/thread.c +++ b/thread.c @@ -367,6 +367,7 @@ rb_thread_terminate_all(void) 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 @@ thread_s_new(int argc, VALUE *argv, VALUE klass) { 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) { -- cgit v1.2.3