From: Nobuyoshi Nakada Date: 2007-08-09T12:28:34+09:00 Subject: Re: Thread.abort_on_exception= in Ruby 1.9 Hi, At Thu, 9 Aug 2007 09:06:30 +0900, Yukihiro Matsumoto wrote in [ruby-core:11877]: > |Thread.abort_on_exception=true is not working the way I would expect it > |to in Ruby 1.9 (my build is from 7/24). > > The 1.9 does not handle abort_on_exception yet. It should be before > the final release. I file this and [ruby-core:11873] (Thread#join > giving wrong backtrace) as bugs. You meant [ruby-core:11874]? Those stackframes seem to be optimized out. Index: thread.c =================================================================== --- thread.c (revision 12908) +++ thread.c (working copy) @@ -278,4 +278,7 @@ thread_cleanup_func(void *th_ptr) } +extern void ruby_error_print(void); +static VALUE rb_thread_raise(int, VALUE *, rb_thread_t *); + static int thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_start) @@ -285,4 +288,7 @@ thread_start_func_2(rb_thread_t *th, VAL rb_proc_t *proc; rb_thread_t *join_th; + rb_thread_t *main_th; + VALUE errinfo = Qnil; + th->machine_stack_start = stack_start; #ifdef __ia64 @@ -314,4 +320,10 @@ thread_start_func_2(rb_thread_t *th, VAL } else { + if (th->safe_level < 4 && + (th->vm->thread_abort_on_exception || + th->abort_on_exception || RTEST(ruby_debug))) { + errinfo = th->errinfo; + if (NIL_P(errinfo)) errinfo = rb_errinfo(); + } th->value = Qnil; } @@ -322,7 +334,11 @@ thread_start_func_2(rb_thread_t *th, VAL st_delete_wrap(th->vm->living_threads, th->self); + main_th = th->vm->main_thread; + if (th == main_th) errinfo = Qnil; + /* wake up joinning threads */ join_th = th->join_list_head; while (join_th) { + if (join_th == main_th) errinfo = Qnil; rb_thread_interrupt(join_th); join_th = join_th->join_list_next; @@ -332,4 +348,10 @@ thread_start_func_2(rb_thread_t *th, VAL thread_cleanup_func(th); native_mutex_unlock(&th->vm->global_interpreter_lock); + + if (!NIL_P(errinfo)) { + /* exit on main_thread */ + rb_thread_raise(1, &errinfo, main_th); + } + return 0; } -- Nobu Nakada