---
name: "thr_self"
section: "2"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/thr_self"
---

# thr\_self(2)

return thread identifier for the calling thread

## NAME

**thr\_self** – return thread identifier for the calling thread

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<sys/thr.h\>**

*int*\

**thr\_self**(*long \*id*);

## DESCRIPTION

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.

## SEE ALSO

[\_umtx\_op(2)](/_umtx_op/2.md), [thr\_exit(2)](/thr_exit/2.md), [thr\_kill(2)](/thr_kill/2.md), [thr\_kill2(2)](/thr_kill2/2.md), [thr\_new(2)](/thr_new/2.md), [thr\_set\_name(2)](/thr_set_name/2.md), [pthread\_getthreadid\_np(3)](/pthread_getthreadid_np/3.md), [pthread\_self(3)](/pthread_self/3.md)

## 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)](/pthread/3.md) functionality.

## HISTORY

The **thr\_self**() system call first appeared in FreeBSD 5.2.
