From: KOSAKI Motohiro Date: 2011-06-18T21:14:50+09:00 Subject: [ruby-core:37218] Re: [Request for Comment] avoid timer thread > From 9154363119cd09a3b79aa45753d177ec65914f7c Mon Sep 17 00:00:00 2001 > From: Eric Wong > Date: Fri, 17 Jun 2011 19:52:48 +0000 > Subject: [PATCH] defer timer thread wakeups after fork() > > There is a small race condition where a signal can be received > immediately after fork() but before the timer thread pipe can be > reinitialized, leading to EPIPE on write(). > > We probably can't disable interrupt before forking due to > system/exec() issues; and we don't want to lose wakeups to the > parent process, so we check the cached pid vs getpid() whenever > rb_thread_wakeup_timer_thread() is called. > --- > �thread_pthread.c | � 15 +++++++++++++++ > �1 files changed, 15 insertions(+), 0 deletions(-) > > diff --git a/thread_pthread.c b/thread_pthread.c > index 1cc212b..3d99974 100644 > --- a/thread_pthread.c > +++ b/thread_pthread.c > @@ -989,11 +989,18 @@ static void ping_signal_thread_list(void) { } > �#endif /* USE_SIGNAL_THREAD_LIST */ > > �static pthread_t timer_thread_id; > +static sig_atomic_t timer_thread_deferred; > +static pid_t timer_thread_pid; > �static int timer_thread_pipe[2]; > > �void > �rb_thread_wakeup_timer_thread(void) > �{ > + � �if (getpid() != timer_thread_pid) { getpid() return *process* id. timer thread and other threads will get the same process id.