Browse files

Fix deadlock in starting a Thread

When we create a new Thread object, it is allocated with a the
initializion lock locked. This means that any other method can needs to
grab this lock has to wait for the thread to be actually started.

If a method such as getting a backtrace of the thread is called before
the thread is scheduled to be started, it can deadlock because it can't
grab the lock and if there is simultanous GC triggered.
  • Loading branch information...
1 parent 7c55367 commit 59ab694c8863c601fc01ad329ad32f518b908b09 @dbussink dbussink committed Oct 4, 2012
Showing with 1 addition and 2 deletions.
  1. +1 −2 vm/builtin/thread.cpp
@@ -77,8 +77,6 @@ namespace rubinius {
- if(!main_thread) thr->init_lock_.lock();
return thr;
@@ -184,6 +182,7 @@ namespace rubinius {
Thread* self = this;
OnStack<1> os(state, self);
+ self->init_lock_.lock();
int error = pthread_create(&vm_->os_thread(), &attrs, in_new_thread, (void*)vm_);
if(error) {
return error;

0 comments on commit 59ab694

Please sign in to comment.