ruby-changes:52277
From: normal <ko1@a...>
Date: Tue, 21 Aug 2018 06:34:44 +0900 (JST)
Subject: [ruby-changes:52277] normal:r64485 (trunk): thread_pthread.c: reinitialize ubf_list at fork
normal 2018-08-21 06:34:39 +0900 (Tue, 21 Aug 2018) New Revision: 64485 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64485 Log: thread_pthread.c: reinitialize ubf_list at fork It's possible for the ubf_list_head to be populated with dead threads at fork or the ubf_list_lock to be held, so reinitialize both at startup. And while we're at it, use a static initializer at startup to save a library call and kill some ifdef. [ruby-core:88578] [Bug #15013] Modified files: trunk/thread.c trunk/thread_pthread.c trunk/thread_win32.c Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 64484) +++ thread_pthread.c (revision 64485) @@ -532,10 +532,6 @@ native_cond_timeout(rb_nativethread_cond https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L532 #define native_cleanup_push pthread_cleanup_push #define native_cleanup_pop pthread_cleanup_pop -#if defined(USE_UBF_LIST) -static rb_nativethread_lock_t ubf_list_lock; -#endif - static pthread_key_t ruby_native_thread_key; static void @@ -574,9 +570,6 @@ Init_native_thread(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L570 th->thread_id = pthread_self(); fill_thread_id_str(th); native_thread_init(th); -#ifdef USE_UBF_LIST - rb_native_mutex_initialize(&ubf_list_lock); -#endif posix_signal(SIGVTALRM, null_func); } @@ -1268,6 +1261,14 @@ native_cond_sleep(rb_thread_t *th, struc https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1261 #ifdef USE_UBF_LIST static LIST_HEAD(ubf_list_head); +static rb_nativethread_lock_t ubf_list_lock = RB_NATIVETHREAD_LOCK_INIT; + +static void +ubf_list_atfork(void) +{ + list_head_init(&ubf_list_head); + rb_native_mutex_initialize(&ubf_list_lock); +} /* The thread 'th' is registered to be trying unblock. */ static void Index: thread_win32.c =================================================================== --- thread_win32.c (revision 64484) +++ thread_win32.c (revision 64485) @@ -23,6 +23,7 @@ https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L23 #define ubf_wakeup_all_threads() do {} while (0) #define ubf_threads_empty() (1) #define ubf_timer_disarm() do {} while (0) +#define ubf_list_atfork() do {} while (0) static volatile DWORD ruby_native_thread_key = TLS_OUT_OF_INDEXES; Index: thread.c =================================================================== --- thread.c (revision 64484) +++ thread.c (revision 64485) @@ -4396,6 +4396,7 @@ rb_thread_atfork_internal(rb_thread_t *t https://github.com/ruby/ruby/blob/trunk/thread.c#L4396 vm->main_thread = th; gvl_atfork(th->vm); + ubf_list_atfork(); list_for_each(&vm->living_threads, i, vmlt_node) { atfork(i, th); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/