thr_self(2)

thr_self2

Return thread identifier for the calling thread

Usage

#include <sys/thr.h>

int

thr_self(long *id);

Library

Standard C Library (libc, -lc)

Overview

The thr_self() system call stores the system-wide thread identifier for the current kernel-scheduled thread in the variable pointed by the argument id.

The thread identifier is an integer in the range from PID_MAX + 2 (100001) to INT_MAX. The thread identifier is guaranteed to be unique at any given time, for each running thread in the system. After the thread exits, the identifier may be reused.

Return values

If successful, thr_self() will return zero, otherwise -1 is returned, and errno is set to indicate the error.

Errors

The thr_self() operation may return the following errors:

[EFAULT]

The memory pointed to by the id argument is not valid.

Releases

25 releases since FreeBSD 11.0-RELEASE; the text changed 12 times.

  1. 11.0
  2. 11.1
  3. 11.2
  4. 11.3
  5. 11.4
  6. 12.0
  7. 12.1
  8. 12.2
  9. 12.3
  10. 12.4
  11. 13.0–13.2
  12. 13.3–14.2
  13. 14.3–16.0

Standards

The thr_self() system call is non-standard and is used by library “libthr” to implement IEEE Std 1003.1-2001 (“POSIX.1”) pthread(3) functionality.

History

The thr_self() system call first appeared in FreeBSD 5.2.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.