* 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
This commit is contained in:
parent
3e0becb42d
commit
f150ed1532
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
Mon Nov 26 17:00:12 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Mon Nov 26 16:36:13 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
Mon Nov 26 16:36:13 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (argf_each_codepoint): add missing ARGF#codepoints [Bug #7438]
|
* io.c (argf_each_codepoint): add missing ARGF#codepoints [Bug #7438]
|
||||||
|
18
signal.c
18
signal.c
@ -17,6 +17,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "ruby_atomic.h"
|
#include "ruby_atomic.h"
|
||||||
|
#include "eval_intern.h"
|
||||||
|
|
||||||
#if defined(__native_client__) && defined(NACL_NEWLIB)
|
#if defined(__native_client__) && defined(NACL_NEWLIB)
|
||||||
# include "nacl/signal.h"
|
# include "nacl/signal.h"
|
||||||
@ -623,7 +624,22 @@ static void
|
|||||||
signal_exec(VALUE cmd, int safe, int sig)
|
signal_exec(VALUE cmd, int safe, int sig)
|
||||||
{
|
{
|
||||||
VALUE signum = INT2NUM(sig);
|
VALUE signum = INT2NUM(sig);
|
||||||
rb_eval_cmd(cmd, rb_ary_new3(1, signum), safe);
|
rb_thread_t *cur_th = GET_THREAD();
|
||||||
|
int old_in_trap = cur_th->in_trap;
|
||||||
|
int state;
|
||||||
|
|
||||||
|
cur_th->in_trap = 1;
|
||||||
|
TH_PUSH_TAG(cur_th);
|
||||||
|
if ((state = EXEC_TAG()) == 0) {
|
||||||
|
rb_eval_cmd(cmd, rb_ary_new3(1, signum), safe);
|
||||||
|
}
|
||||||
|
TH_POP_TAG();
|
||||||
|
cur_th->in_trap = old_in_trap;
|
||||||
|
|
||||||
|
if (state) {
|
||||||
|
/* XXX: should be replaced with rb_threadptr_async_errinfo_enque() */
|
||||||
|
JUMP_TAG(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -863,4 +863,19 @@ class TestThreadGroup < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
assert_in_delta(t1 - t0, 1, 1, bug5757)
|
assert_in_delta(t1 - t0, 1, 1, bug5757)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_thread_join_in_trap
|
||||||
|
assert_raise(ThreadError) {
|
||||||
|
t = Thread.new{ sleep 0.2; Process.kill(:INT, $$) }
|
||||||
|
|
||||||
|
Signal.trap :INT do
|
||||||
|
t.join
|
||||||
|
end
|
||||||
|
|
||||||
|
t.join
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
9
thread.c
9
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);
|
th->async_errinfo_mask_stack = rb_ary_dup(current_th->async_errinfo_mask_stack);
|
||||||
RBASIC(th->async_errinfo_mask_stack)->klass = 0;
|
RBASIC(th->async_errinfo_mask_stack)->klass = 0;
|
||||||
|
|
||||||
|
th->in_trap = 0;
|
||||||
|
|
||||||
native_mutex_initialize(&th->interrupt_lock);
|
native_mutex_initialize(&th->interrupt_lock);
|
||||||
|
|
||||||
/* kick thread */
|
/* kick thread */
|
||||||
@ -790,9 +792,14 @@ static VALUE
|
|||||||
thread_join_m(int argc, VALUE *argv, VALUE self)
|
thread_join_m(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
rb_thread_t *target_th;
|
rb_thread_t *target_th;
|
||||||
|
rb_thread_t *cur_th = GET_THREAD();
|
||||||
double delay = DELAY_INFTY;
|
double delay = DELAY_INFTY;
|
||||||
VALUE limit;
|
VALUE limit;
|
||||||
|
|
||||||
|
if (cur_th->in_trap) {
|
||||||
|
rb_raise(rb_eThreadError, "can't be called from trap context");
|
||||||
|
}
|
||||||
|
|
||||||
GetThreadPtr(self, target_th);
|
GetThreadPtr(self, target_th);
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "01", &limit);
|
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 = rb_ary_tmp_new(0);
|
||||||
th->async_errinfo_queue_checked = 0;
|
th->async_errinfo_queue_checked = 0;
|
||||||
th->async_errinfo_mask_stack = rb_ary_tmp_new(0);
|
th->async_errinfo_mask_stack = rb_ary_tmp_new(0);
|
||||||
|
|
||||||
|
th->in_trap = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user