From f150ed1532e727c409cc018a98e1362a8c71242c Mon Sep 17 00:00:00 2001 From: kosaki Date: Mon, 26 Nov 2012 08:05:49 +0000 Subject: * vm_core.h (rb_thread_struct): added 'in_trap' member for marking running trap handler. * signal.c (signal_exec): turn on in_trap when running trap. * thread.c (Init_Thread, thread_create_core): initialize in_trap when creating new threads. * thread.c (thread_join_m): raise ThreadError when running trap handler.Bug [#6416][ruby-core:44956] * test/ruby/test_thread.rb (test_thread_join_in_trap): new test for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'thread.c') diff --git a/thread.c b/thread.c index 64eaadc9b5..3af7a0fee4 100644 --- a/thread.c +++ b/thread.c @@ -567,6 +567,8 @@ thread_create_core(VALUE thval, VALUE args, VALUE (*fn)(ANYARGS)) th->async_errinfo_mask_stack = rb_ary_dup(current_th->async_errinfo_mask_stack); RBASIC(th->async_errinfo_mask_stack)->klass = 0; + th->in_trap = 0; + native_mutex_initialize(&th->interrupt_lock); /* kick thread */ @@ -790,9 +792,14 @@ static VALUE thread_join_m(int argc, VALUE *argv, VALUE self) { rb_thread_t *target_th; + rb_thread_t *cur_th = GET_THREAD(); double delay = DELAY_INFTY; VALUE limit; + if (cur_th->in_trap) { + rb_raise(rb_eThreadError, "can't be called from trap context"); + } + GetThreadPtr(self, target_th); rb_scan_args(argc, argv, "01", &limit); @@ -4773,6 +4780,8 @@ Init_Thread(void) th->async_errinfo_queue = rb_ary_tmp_new(0); th->async_errinfo_queue_checked = 0; th->async_errinfo_mask_stack = rb_ary_tmp_new(0); + + th->in_trap = 0; } } -- cgit v1.2.3