summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-11 04:15:29 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-11 04:15:29 +0000
commit14a97fd48aad077f7e239a20dd30cad41c0f6d8f (patch)
tree27e677526f591c29820e9d781c0f3409069d7c48 /thread.c
parent427347626599135f6b9aa84018df8ac23685c35f (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/thread.c b/thread.c
index 21d43edc27..5b48721e71 100644
--- a/thread.c
+++ b/thread.c
@@ -273,7 +273,7 @@ rb_thread_terminate_all(void)
}
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 @@ thread_cleanup_func(void *th_ptr)
#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 @@ rb_thread_atfork(void)
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;