diff --git a/ChangeLog b/ChangeLog index e10e8438ba..48bcd2d3e9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Dec 29 23:59:37 2005 Nobuyoshi Nakada + + * eval.c (rb_gc_mark_threads): keep unmarked threads which won't wake + up alone, and mark threads in the loading table. [ruby-dev:28154] + + * eval.c (rb_gc_abort_threads), gc.c (gc_sweep): kill unmarked + threads. [ruby-dev:28172] + Thu Dec 29 17:02:07 2005 Tanaka Akira * test/ruby/envutil.rb (EnvUtil.rubybin): search "ruby" instead of diff --git a/eval.c b/eval.c index 21842c91b0..745f08fb23 100644 --- a/eval.c +++ b/eval.c @@ -9987,6 +9987,13 @@ static struct { VALUE proc, arg; } new_thread; +static int +mark_loading_thread(ID key, VALUE value, int lev) +{ + rb_gc_mark(((rb_thread_t)value)->thread); + return ST_CONTINUE; +} + void rb_gc_mark_threads(void) { @@ -9996,7 +10003,18 @@ rb_gc_mark_threads(void) rb_gc_mark((VALUE)ruby_cref); if (!curr_thread) return; + rb_gc_mark(main_thread->thread); + rb_gc_mark(curr_thread->thread); FOREACH_THREAD_FROM(main_thread, th) { + switch (th->status) { + case THREAD_TO_KILL: + case THREAD_RUNNABLE: + break; + case THREAD_STOPPED: + if (th->wait_for) break; + default: + continue; + } rb_gc_mark(th->thread); } END_FOREACH_FROM(main_thread, th); if (new_thread.thread) { @@ -10004,6 +10022,21 @@ rb_gc_mark_threads(void) rb_gc_mark(new_thread.proc); rb_gc_mark(new_thread.arg); } + if (loading_tbl) st_foreach(loading_tbl, mark_loading_thread, 0); +} + +void +rb_gc_abort_threads(void) +{ + rb_thread_t th; + + FOREACH_THREAD_FROM(main_thread, th) { + if (FL_TEST(th->thread, FL_MARK)) continue; + if (th->status == THREAD_STOPPED) { + th->status = THREAD_TO_KILL; + rb_gc_mark(th->thread); + } + } END_FOREACH_FROM(main_thread, th); } static void diff --git a/gc.c b/gc.c index 19de920505..ea4d3b0078 100644 --- a/gc.c +++ b/gc.c @@ -1015,6 +1015,8 @@ gc_sweep(void) st_foreach(source_filenames, sweep_source_filename, 0); } + rb_gc_abort_threads(); + freelist = 0; final_list = deferred_final_list; deferred_final_list = 0;