summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-20 21:34:39 (GMT)
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-20 21:34:39 (GMT)
commit17e4aff277a350fa6afea31bc521c9a3f4f47353 (patch)
tree90ba3ef3466488f774f2d9dd3a6277b2e0ab3816 /thread_pthread.c
parentce48b55805873ad3913be832e919e3ebe8b8f7a3 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index 2fd60dd..2923c15 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -532,10 +532,6 @@ native_cond_timeout(rb_nativethread_cond_t *cond, struct timespec timeout_rel)
#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)
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, struct timespec *timeout_rel)
#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