1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Transition root fiber into state FIBER_TERMINATED.

During fork, it's possible that threads with root fibers are terminated,
but fiber state is not updated. `fiber_verify` will subsequently fail. We
forcefully enter the FIBER_TERMINATED state when terminating the root
fiber.
This commit is contained in:
Samuel Williams 2019-06-20 20:29:35 +12:00
parent 3077cb6912
commit f607e43352
2 changed files with 14 additions and 2 deletions

11
cont.c
View file

@ -1581,6 +1581,17 @@ rb_threadptr_root_fiber_release(rb_thread_t *th)
} }
} }
void
rb_threadptr_root_fiber_terminate(rb_thread_t *th)
{
rb_fiber_t *fiber = th->ec->fiber_ptr;
fiber->status = FIBER_TERMINATED;
// The vm_stack is `alloca`ed on the thread stack, so it's gone too:
rb_ec_clear_vm_stack(th->ec);
}
static inline rb_fiber_t* static inline rb_fiber_t*
fiber_current(void) fiber_current(void)
{ {

View file

@ -591,6 +591,8 @@ rb_thread_terminate_all(void)
EC_POP_TAG(); EC_POP_TAG();
} }
void rb_threadptr_root_fiber_terminate(rb_thread_t *th);
static void static void
thread_cleanup_func_before_exec(void *th_ptr) thread_cleanup_func_before_exec(void *th_ptr)
{ {
@ -599,8 +601,7 @@ thread_cleanup_func_before_exec(void *th_ptr)
// The thread stack doesn't exist in the forked process: // The thread stack doesn't exist in the forked process:
th->ec->machine.stack_start = th->ec->machine.stack_end = NULL; th->ec->machine.stack_start = th->ec->machine.stack_end = NULL;
// The vm_stack is `alloca`ed on the thread stack, so it's gone too: rb_threadptr_root_fiber_terminate(th);
rb_ec_clear_vm_stack(th->ec);
} }
static void static void