Method: Thread#terminate

Defined in:
thread.c

#exitnil #killnil #terminatenil

Terminates thr and schedules another thread to be run.

If this thread is already marked to be killed, #exit returns the Thread.

If this is the main thread, or the last thread, exits the process.

Overloads:

  • #exitnil

    Returns:

    • (nil)
  • #killnil

    Returns:

    • (nil)
  • #terminatenil

    Returns:

    • (nil)


2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
# File 'thread.c', line 2183

VALUE
rb_thread_kill(VALUE thread)
{
    rb_thread_t *th;

    GetThreadPtr(thread, th);

    if (th->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);

    if (th == GET_THREAD()) {
	/* kill myself immediately */
	rb_threadptr_to_kill(th);
    }
    else {
	rb_threadptr_pending_interrupt_enque(th, eKillSignal);
	rb_threadptr_interrupt(th);
    }
    return thread;
}