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
This commit is contained in:
normal 2018-05-24 02:52:46 +00:00
Родитель fa31e1a418
Коммит 72ad081145
1 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -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);