Detach a pthread after pthread_setaffinity_np
After a pthread for getaddrinfo is detached, we cannot predict when the thread will exit. It would lead to a segfault by setting pthread_setaffinity to the terminated pthread. I guess this problem would be more likely to occur in high-load environments. This change detaches the pthread after pthread_setaffinity is called. [Feature #19965]
This commit is contained in:
parent
15560cce5f
commit
d0066211f2
@ -481,13 +481,13 @@ start:
|
|||||||
return EAI_AGAIN;
|
return EAI_AGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_detach(th);
|
|
||||||
#if defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(HAVE_SCHED_GETCPU)
|
#if defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(HAVE_SCHED_GETCPU)
|
||||||
cpu_set_t tmp_cpu_set;
|
cpu_set_t tmp_cpu_set;
|
||||||
CPU_ZERO(&tmp_cpu_set);
|
CPU_ZERO(&tmp_cpu_set);
|
||||||
CPU_SET(sched_getcpu(), &tmp_cpu_set);
|
CPU_SET(sched_getcpu(), &tmp_cpu_set);
|
||||||
pthread_setaffinity_np(th, sizeof(cpu_set_t), &tmp_cpu_set);
|
pthread_setaffinity_np(th, sizeof(cpu_set_t), &tmp_cpu_set);
|
||||||
#endif
|
#endif
|
||||||
|
pthread_detach(th);
|
||||||
|
|
||||||
rb_thread_call_without_gvl2(wait_getaddrinfo, arg, cancel_getaddrinfo, arg);
|
rb_thread_call_without_gvl2(wait_getaddrinfo, arg, cancel_getaddrinfo, arg);
|
||||||
|
|
||||||
@ -700,13 +700,13 @@ start:
|
|||||||
return EAI_AGAIN;
|
return EAI_AGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_detach(th);
|
|
||||||
#if defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(HAVE_SCHED_GETCPU)
|
#if defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(HAVE_SCHED_GETCPU)
|
||||||
cpu_set_t tmp_cpu_set;
|
cpu_set_t tmp_cpu_set;
|
||||||
CPU_ZERO(&tmp_cpu_set);
|
CPU_ZERO(&tmp_cpu_set);
|
||||||
CPU_SET(sched_getcpu(), &tmp_cpu_set);
|
CPU_SET(sched_getcpu(), &tmp_cpu_set);
|
||||||
pthread_setaffinity_np(th, sizeof(cpu_set_t), &tmp_cpu_set);
|
pthread_setaffinity_np(th, sizeof(cpu_set_t), &tmp_cpu_set);
|
||||||
#endif
|
#endif
|
||||||
|
pthread_detach(th);
|
||||||
|
|
||||||
rb_thread_call_without_gvl2(wait_getnameinfo, arg, cancel_getnameinfo, arg);
|
rb_thread_call_without_gvl2(wait_getnameinfo, arg, cancel_getnameinfo, arg);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user