From 72ad081145fee3ebd444fbc437f1538d083ded90 Mon Sep 17 00:00:00 2001 From: normal Date: Thu, 24 May 2018 02:52:46 +0000 Subject: thread_pthread.c: avoid reading th pointer for thread cache I suspect GC may free the rb_thread_t (th) pointer by the time we call register_cached_thread_and_wait. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_pthread.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'thread_pthread.c') diff --git a/thread_pthread.c b/thread_pthread.c index 91d7215914..e17ca36819 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -436,7 +436,7 @@ native_thread_destroy(rb_thread_t *th) #endif #if USE_THREAD_CACHE -static rb_thread_t *register_cached_thread_and_wait(rb_nativethread_id_t); +static rb_thread_t *register_cached_thread_and_wait(void); #endif #if defined HAVE_PTHREAD_GETATTR_NP || defined HAVE_PTHREAD_ATTR_GET_NP @@ -841,7 +841,7 @@ thread_start_func_1(void *th_ptr) #if USE_THREAD_CACHE if (1) { /* cache thread */ - if ((th = register_cached_thread_and_wait(th->thread_id)) != 0) { + if ((th = register_cached_thread_and_wait()) != 0) { goto thread_start; } } @@ -880,14 +880,14 @@ thread_cache_reset(void) #endif static rb_thread_t * -register_cached_thread_and_wait(rb_nativethread_id_t thread_self_id) +register_cached_thread_and_wait(void) { struct timespec end = { THREAD_CACHE_TIME, 0 }; struct cached_thread_entry entry; rb_native_cond_initialize(&entry.cond); entry.th = NULL; - entry.thread_id = thread_self_id; + entry.thread_id = pthread_self(); end = native_cond_timeout(&entry.cond, end); rb_native_mutex_lock(&thread_cache_lock); -- cgit v1.2.3