From: Yukihiro Matsumoto Date: 2005-02-22T12:57:32+09:00 Subject: [ruby-dev:25742] Re: core dump with GC in rb_thread_save_context まつもと ゆきひろです In message "Re: [ruby-dev:25712] core dump with GC in rb_thread_save_context" on Fri, 18 Feb 2005 08:09:28 +0900, Tanaka Akira writes: |昨日の夜からとあるプログラム (五月雨) が 4回ばかり core を吐いていて、 |それらで最後に GC が起きた所が一致しています。 分かりました。スレッド生成のためスタックを巻き戻している最中 にGCが起きると * curr_threadは生成元のスレッドを指している * が、スレッド生成のためスタックは巻き戻されている ために生成元スタックがスキャンされず、オブジェクトがことごと くGCに回収されてしまっていました。そこで、TAG_THREADをraise する前にcurr_thread=thの設定と、thread_insert(th)の呼び出し を行ってしまうことにしました。これはこれで問題を引き起こしそ うですが。 ついでに、new_threadの内容もGCスキャンするようにしてみました が、こちらは不要だったかもしれません。 Tue Feb 22 12:54:13 2005 Yukihiro Matsumoto * eval.c (rb_thread_start_0): update curr_thread before raising TAG_THREAD. [ruby-dev:25712] --- eval.c 17 Feb 2005 14:29:20 -0000 1.754 +++ eval.c 22 Feb 2005 03:55:30 -0000 @@ -9943,2 +9951,7 @@ thread_mark(th) +static struct { + rb_thread_t thread; + VALUE proc, arg; +} new_thread; + void @@ -9955,2 +9968,7 @@ rb_gc_mark_threads() } END_FOREACH(th); + if (new_thread.thread) { + rb_gc_mark(new_thread.thread->thread); + rb_gc_mark(new_thread.proc); + rb_gc_mark(new_thread.arg); + } } @@ -11605,7 +11624,2 @@ thread_insert(th) -static struct { - rb_thread_t thread; - VALUE proc, arg; -} new_thread; - static VALUE @@ -11654,2 +11668,4 @@ rb_thread_start_0(fn, arg, th) th->anchor = ip; + thread_insert(th); + curr_thread = th; longjmp((prot_tag = ip->tag)->buf, TAG_THREAD); @@ -11749,4 +11765,2 @@ rb_thread_start_1() - thread_insert(th); - ruby_frame = ip->frame; @@ -11764,2 +11778,3 @@ rb_thread_start_1() if (THREAD_SAVE_CONTEXT(th) == 0) { + new_thread.thread = 0; curr_thread = th;