ruby-changes:4862
From: ko1@a...
Date: Sun, 11 May 2008 13:15:47 +0900 (JST)
Subject: [ruby-changes:4862] akr - Ruby:r16355 (trunk): * thread.c (thread_cleanup_func_before_exec): extracted from
akr 2008-05-11 13:15:29 +0900 (Sun, 11 May 2008) New Revision: 16355 Modified files: trunk/ChangeLog trunk/include/ruby/intern.h trunk/io.c trunk/process.c trunk/thread.c Log: * thread.c (thread_cleanup_func_before_exec): extracted from thread_cleanup_func not to touch pthread data. pthread_cond_destroy in forked process may cause deadlock on Debian GNU/Linux Etch on x86, x86-64 and IA64. this doesn't cause resource leak because the process will exec soon. (terminate_atfork_before_exec_i): defined. (rb_thread_atfork_before_exec): defined. * include/ruby/intern.h (rb_thread_atfork_before_exec): declared. * process.c (rb_exec_atfork): call rb_thread_atfork_before_exec instead of rb_thread_atfork. * io.c (popen_exec): call rb_thread_atfork_before_exec instead of rb_thread_atfork. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16355&r2=16354&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/thread.c?r1=16355&r2=16354&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/io.c?r1=16355&r2=16354&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/process.c?r1=16355&r2=16354&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/intern.h?r1=16355&r2=16354&diff_format=u Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 16354) +++ include/ruby/intern.h (revision 16355) @@ -308,6 +308,7 @@ VALUE rb_thread_local_aref(VALUE, ID); VALUE rb_thread_local_aset(VALUE, ID, VALUE); void rb_thread_atfork(void); +void rb_thread_atfork_before_exec(void); VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE); /* file.c */ VALUE rb_file_s_expand_path(int, VALUE *); Index: ChangeLog =================================================================== --- ChangeLog (revision 16354) +++ ChangeLog (revision 16355) @@ -1,3 +1,21 @@ +Sun May 11 13:14:09 2008 Tanaka Akira <akr@f...> + + * thread.c (thread_cleanup_func_before_exec): extracted from + thread_cleanup_func not to touch pthread data. + pthread_cond_destroy in forked process may cause deadlock on + Debian GNU/Linux Etch on x86, x86-64 and IA64. + this doesn't cause resource leak because the process will exec soon. + (terminate_atfork_before_exec_i): defined. + (rb_thread_atfork_before_exec): defined. + + * include/ruby/intern.h (rb_thread_atfork_before_exec): declared. + + * process.c (rb_exec_atfork): call rb_thread_atfork_before_exec + instead of rb_thread_atfork. + + * io.c (popen_exec): call rb_thread_atfork_before_exec instead of + rb_thread_atfork. + Sat May 10 22:14:03 2008 Yukihiro Matsumoto <matz@r...> * string.c (tr_trans): single '^' does not mean negation. Index: io.c =================================================================== --- io.c (revision 16354) +++ io.c (revision 16355) @@ -3671,7 +3671,7 @@ { struct popen_arg *p = (struct popen_arg*)pp; - rb_thread_atfork(); + rb_thread_atfork_before_exec(); return rb_exec(p->execp); } #endif Index: thread.c =================================================================== --- thread.c (revision 16354) +++ thread.c (revision 16355) @@ -273,7 +273,7 @@ } static void -thread_cleanup_func(void *th_ptr) +thread_cleanup_func_before_exec(void *th_ptr) { rb_thread_t *th = th_ptr; th->status = THREAD_KILLED; @@ -281,6 +281,13 @@ #ifdef __ia64 th->machine_register_stack_start = th->machine_register_stack_end = 0; #endif +} + +static void +thread_cleanup_func(void *th_ptr) +{ + rb_thread_t *th = th_ptr; + thread_cleanup_func_before_exec(th_ptr); native_thread_destroy(th); } @@ -2064,6 +2071,32 @@ st_insert(vm->living_threads, thval, (st_data_t) th->thread_id); } +static int +terminate_atfork_before_exec_i(st_data_t key, st_data_t val, rb_thread_t *current_th) +{ + VALUE thval = key; + rb_thread_t *th; + GetThreadPtr(thval, th); + + if (th != current_th) { + thread_cleanup_func_before_exec(th); + } + return ST_CONTINUE; +} + +void +rb_thread_atfork_before_exec(void) +{ + rb_thread_t *th = GET_THREAD(); + rb_vm_t *vm = th->vm; + VALUE thval = th->self; + vm->main_thread = th; + + st_foreach(vm->living_threads, terminate_atfork_before_exec_i, (st_data_t)th); + st_clear(vm->living_threads); + st_insert(vm->living_threads, thval, (st_data_t) th->thread_id); +} + struct thgroup { int enclosed; VALUE group; Index: process.c =================================================================== --- process.c (revision 16354) +++ process.c (revision 16355) @@ -2103,7 +2103,7 @@ static int rb_exec_atfork(void* arg) { - rb_thread_atfork(); + rb_thread_atfork_before_exec(); return rb_exec(arg); } #endif -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/