Skip to content

Commit

Permalink
Fixed deadlock with managed phase and Fiber switching.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Jun 20, 2016
1 parent f5ddf1e commit 14e9e54
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions machine/builtin/fiber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ namespace rubinius {
}

void Fiber::restart(STATE) {
UnmanagedPhase unmanaged(state);

{
std::lock_guard<std::mutex> guard(state->vm()->thread()->fiber_mutex());

Expand All @@ -88,13 +90,9 @@ namespace rubinius {
restart_context(state->vm());
wakeup();

{
UnmanagedPhase unmanaged(state);

while(vm()->suspended_p()) {
std::lock_guard<std::mutex> guard(vm()->wait_mutex());
vm()->wait_condition().notify_one();
}
while(vm()->suspended_p()) {
std::lock_guard<std::mutex> guard(vm()->wait_mutex());
vm()->wait_condition().notify_one();
}
}

Expand All @@ -104,16 +102,14 @@ namespace rubinius {
}

void Fiber::suspend_and_continue(STATE) {
UnmanagedPhase unmanaged(state);

{
std::unique_lock<std::mutex> lk(vm()->wait_mutex());

vm()->set_suspended();
{
UnmanagedPhase unmanaged(state);

while(!wakeup_p()) {
vm()->wait_condition().wait(lk);
}
while(!wakeup_p()) {
vm()->wait_condition().wait(lk);
}
clear_wakeup();
vm()->set_resuming();
Expand Down Expand Up @@ -217,7 +213,7 @@ namespace rubinius {
* means of expressing things like Fiber.current.
*/
Fiber* Fiber::create(STATE, VM* vm) {
Fiber* fiber = state->memory()->new_object<Fiber>(state, G(fiber));
Fiber* fiber = state->memory()->new_object_pinned<Fiber>(state, G(fiber));

vm->set_fiber(fiber);
vm->set_running();
Expand All @@ -234,7 +230,7 @@ namespace rubinius {
}

Fiber* Fiber::create(STATE, Object* self, Object* stack_size, Object* block) {
Fiber* fiber = state->memory()->new_object<Fiber>(state, as<Class>(self));
Fiber* fiber = state->memory()->new_object_pinned<Fiber>(state, as<Class>(self));
fiber->block(state, block);

std::ostringstream name;
Expand Down

0 comments on commit 14e9e54

Please sign in to comment.