Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method · added in Ruby 3.1

Thread#native_thread_id

() -> ::Integer
thr.native_thread_id → integer

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

  1. 3.1
See also #name= #pending_interrupt? #name #priority also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1