thread_pthread: retry timer thread creation w/o attr on EINVAL
Setting a small stack size can fail due to having 3rd-party libraries (e.g. libkqueue) loaded, if those libraries use thread-local-storage (__thread) heavily. This causes pthread_create to fail with small stacks; even if our timer_thread function does not hit any of the TLS-using code paths. Today, some RubyGems are capable of using libkqueue (or __thread storage directly), and future versions of Ruby may use kqueue internally. cf. https://www.akkadia.org/drepper/tls.pdf git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
de5e3475c0
commit
410362f6a2
@ -1587,6 +1587,7 @@ rb_thread_create_timer_thread(void)
|
|||||||
int err;
|
int err;
|
||||||
#ifdef HAVE_PTHREAD_ATTR_INIT
|
#ifdef HAVE_PTHREAD_ATTR_INIT
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
|
rb_vm_t *vm = GET_VM();
|
||||||
|
|
||||||
err = pthread_attr_init(&attr);
|
err = pthread_attr_init(&attr);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
@ -1623,10 +1624,20 @@ rb_thread_create_timer_thread(void)
|
|||||||
rb_bug("rb_thread_create_timer_thread: Timer thread was already created\n");
|
rb_bug("rb_thread_create_timer_thread: Timer thread was already created\n");
|
||||||
}
|
}
|
||||||
#ifdef HAVE_PTHREAD_ATTR_INIT
|
#ifdef HAVE_PTHREAD_ATTR_INIT
|
||||||
err = pthread_create(&timer_thread.id, &attr, thread_timer, &GET_VM()->gvl);
|
err = pthread_create(&timer_thread.id, &attr, thread_timer, &vm->gvl);
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
|
|
||||||
|
if (err == EINVAL) {
|
||||||
|
/*
|
||||||
|
* Even if we are careful with our own stack use in thread_timer(),
|
||||||
|
* any third-party libraries (eg libkqueue) which rely on __thread
|
||||||
|
* storage can cause small stack sizes to fail. So lets hope the
|
||||||
|
* default stack size is enough for them:
|
||||||
|
*/
|
||||||
|
err = pthread_create(&timer_thread.id, NULL, thread_timer, &vm->gvl);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
err = pthread_create(&timer_thread.id, NULL, thread_timer, &GET_VM()->gvl);
|
err = pthread_create(&timer_thread.id, NULL, thread_timer, &vm->gvl);
|
||||||
#endif
|
#endif
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
rb_warn("pthread_create failed for timer: %s, scheduling broken",
|
rb_warn("pthread_create failed for timer: %s, scheduling broken",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user