Skip to content

Commit 14e9e54

Browse files
committed
Fixed deadlock with managed phase and Fiber switching.
1 parent f5ddf1e commit 14e9e54

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

machine/builtin/fiber.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ namespace rubinius {
7474
}
7575

7676
void Fiber::restart(STATE) {
77+
UnmanagedPhase unmanaged(state);
78+
7779
{
7880
std::lock_guard<std::mutex> guard(state->vm()->thread()->fiber_mutex());
7981

@@ -88,13 +90,9 @@ namespace rubinius {
8890
restart_context(state->vm());
8991
wakeup();
9092

91-
{
92-
UnmanagedPhase unmanaged(state);
93-
94-
while(vm()->suspended_p()) {
95-
std::lock_guard<std::mutex> guard(vm()->wait_mutex());
96-
vm()->wait_condition().notify_one();
97-
}
93+
while(vm()->suspended_p()) {
94+
std::lock_guard<std::mutex> guard(vm()->wait_mutex());
95+
vm()->wait_condition().notify_one();
9896
}
9997
}
10098

@@ -104,16 +102,14 @@ namespace rubinius {
104102
}
105103

106104
void Fiber::suspend_and_continue(STATE) {
105+
UnmanagedPhase unmanaged(state);
106+
107107
{
108108
std::unique_lock<std::mutex> lk(vm()->wait_mutex());
109109

110110
vm()->set_suspended();
111-
{
112-
UnmanagedPhase unmanaged(state);
113-
114-
while(!wakeup_p()) {
115-
vm()->wait_condition().wait(lk);
116-
}
111+
while(!wakeup_p()) {
112+
vm()->wait_condition().wait(lk);
117113
}
118114
clear_wakeup();
119115
vm()->set_resuming();
@@ -217,7 +213,7 @@ namespace rubinius {
217213
* means of expressing things like Fiber.current.
218214
*/
219215
Fiber* Fiber::create(STATE, VM* vm) {
220-
Fiber* fiber = state->memory()->new_object<Fiber>(state, G(fiber));
216+
Fiber* fiber = state->memory()->new_object_pinned<Fiber>(state, G(fiber));
221217

222218
vm->set_fiber(fiber);
223219
vm->set_running();
@@ -234,7 +230,7 @@ namespace rubinius {
234230
}
235231

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

240236
std::ostringstream name;

0 commit comments

Comments
 (0)