Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
Thread#native_thread_id
static VALUE
rb_thread_native_thread_id(VALUE thread)
{
rb_thread_t *target_th = rb_thread_ptr(thread);
if (rb_threadptr_dead(target_th)) return Qnil;
return native_thread_native_thread_id(target_th);
}
Return the native thread ID which is used by the Ruby thread.
The ID depends on the OS. (not POSIX thread ID returned by pthread_self(3))
-
On Linux it is TID returned by gettid(2).
-
On macOS it is the system-wide unique integral ID of thread returned by pthread_threadid_np(3).
-
On FreeBSD it is the unique integral ID of the thread returned by pthread_getthreadid_np(3).
-
On Windows it is the thread identifier returned by GetThreadId().
-
On other platforms, it raises
NotImplementedError.
NOTE: If the thread is not associated yet or already deassociated with a native thread, it returns nil. If the Ruby implementation uses M:N thread model, the ID may change depending on the timing.
Ruby version changes
-
3.1
-
Thread#native_thread_idis added. [Feature #17853]
-