THR_SELF(2)

πŸ’– THR_SELF πŸ’–

okay so bestie, welcome to the thr_self(2) page, aka the "who even am I" syscall, and honestly? it's giving self-discovery era 🌸. this one lives in the System Calls Manual, and it's here to hand you the thread identifier of the calling thread. no cap.

✨ LIBRARY ✨

Standard C Library (libc, -lc) 🫢


🌈 SYNOPSIS 🌈

#include <sys/thr.h>

int
thr_self(long *id);

πŸ‘‘ DESCRIPTION πŸ‘‘

so here's the tea β˜•: the thr_self() system call stores the system-wide thread identifier for the current kernel-scheduled thread into the variable that the argument id points at. that's it. that's the whole vibe. she's simple, she's iconic πŸ’….

now, the thread identifier itself? it's an integer, and it lives in the range from PID_MAX + 2 (10002) all the way up to INT_MAX. yes, that's the whole neighborhood 🏘️.

and listen β€” the thread identifier is guaranteed to be unique at any given time, for each running thread in the system. so no two threads are out here sharing an ID at the same moment. periodt. ✨

but bestie, heads up πŸ™ˆ: after the thread exits, the identifier may be reused. so don't go treating it like a forever tattoo, okay? it's more of a temporary situationship πŸ’€.

πŸŽ€ RETURN VALUES πŸŽ€

if everything slays, thr_self() returns zero πŸ₯³. otherwise it hands you back -1, and errno gets set to tell you what went wrong. she's dramatic like that.

πŸ’… ERRORS πŸ’…

the thr_self() operation may return the following errors:

  • [EFAULT] β€” the memory that the id argument points to is not valid 😭. like, girl, that pointer is not it.

πŸ¦‹ SEE ALSO πŸ¦‹

go read those too, iykyk πŸ‘‘

⭐ STANDARDS ⭐

real talk: the thr_self() system call is non-standard, bestie. she doesn't play by the ISO rules, she makes her own 🌈. she's used by the 1:1 Threading Library (libthr, -lthr) to implement IEEE Std 1003.1-2001 (β€œPOSIX.1”) pthread(3) functionality. so like, she's the backstage crew making the main character shine ✨.


and that's the whole page, babe 🫢 this came to you courtesy of Debian, dated June 1, 2016 β€” so yeah, she's been iconic for a minute. stay unique (at any given time) and don't get recycled πŸ’–πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from