Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created May 31, 2009 11:42
Show Gist options
  • Select an option

  • Save methodmissing/120856 to your computer and use it in GitHub Desktop.

Select an option

Save methodmissing/120856 to your computer and use it in GitHub Desktop.
static void
rb_kill_thread(th, flags)
rb_thread_t th;
int flags;
{
if (th != curr_thread && th->safe < 4) {
rb_secure(4);
}
if (th->status == THREAD_TO_KILL || th->status == THREAD_KILLED)
return;
if (th == th->next || th == main_thread) rb_exit(EXIT_SUCCESS);
rb_thread_ready(th);
th->flags |= flags;
th->status = THREAD_TO_KILL;
if (!rb_thread_critical) rb_thread_schedule();
}
VALUE
rb_thread_kill(VALUE thread)
{
rb_thread_t *th;
GetThreadPtr(thread, th);
if (th != GET_THREAD() && th->safe_level < 4) {
rb_secure(4);
}
if (th->status == THREAD_TO_KILL || th->status == THREAD_KILLED) {
return thread;
}
if (th == th->vm->main_thread) {
rb_exit(EXIT_SUCCESS);
}
thread_debug("rb_thread_kill: %p (%p)\n", (void *)th, (void *)th->thread_id);
rb_thread_interrupt(th);
th->thrown_errinfo = eKillSignal;
th->status = THREAD_TO_KILL;
return thread;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment