ruby-changes:51293
From: normal <ko1@a...>
Date: Thu, 24 May 2018 11:52:55 +0900 (JST)
Subject: [ruby-changes:51293] normal:r63499 (trunk): thread_pthread.c: avoid reading th pointer for thread cache
normal 2018-05-24 11:52:46 +0900 (Thu, 24 May 2018) New Revision: 63499 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63499 Log: 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. Modified files: trunk/thread_pthread.c Index: thread_pthread.c =================================================================== --- thread_pthread.c (revision 63498) +++ thread_pthread.c (revision 63499) @@ -436,7 +436,7 @@ native_thread_destroy(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L436 #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) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L841 #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) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L880 #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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/