THR_EXIT(2)

πŸ’– THR_EXIT πŸ’–

okay bestie, so this one is from the System Calls Manual section β€” it's thr_exit, and it's giving "terminate current thread" energy. let's get into it πŸ¦‹


✨ NAME ✨

thr_exit β€” terminate current thread πŸ’…


πŸ“š LIBRARY πŸ“š

Standard C Library β€” that's libc, linked with -lc. yep, she's a libc girlie πŸŽ€


🌸 SYNOPSIS 🌸

#include <sys/thr.h>

void
thr_exit(long *state);

🫢 DESCRIPTION 🫢

okay so real talk: this function is literally intended for implementing threading. if you're just a normal application doing normal application things, you should be calling pthread_exit(3) instead. no cap. thr_exit is the low-level machinery, not the vibe you want to be messing with unless you're literally building a threading library πŸ’€

The thr_exit() system call terminates the current kernel-scheduled thread. periodt.

Now, if the state argument is not NULL, the location that the argument points to gets updated with an arbitrary non-zero value, and an _umtx_op(2) UMTX_OP_WAKE operation is consequently performed on that location. (yes bestie, arbitrary β€” don't go assuming it's your thread id or anything cute like that, it's just... a non-zero value. it is what it is πŸ™ˆ)

⚠️ big warning energy: attempts to terminate the last thread in the process are silently ignored. like, no error, no nothing, just vibes and a shrug. if you actually want the process gone-gone, use the _exit(2) syscall to terminate the process. that's the move πŸ‘‘

⭐ RETURN VALUES ⭐

The function does not return a value. that's the whole point, she exits.

but lowkey, if you do see a return from this function? that means the calling thread was the last one in the process. so like... if you get a return, that's your sign. main character moment, but also kind of a jumpscare 😭


πŸ‘€ SEE ALSO πŸ‘€


🌈 STANDARDS 🌈

The thr_exit() system call is non-standard β€” she's not in any official spec, she's just doing her own thing. she's used by the 1:1 Threading Library (libthr, -lthr) to implement the IEEE Std 1003.1-2001 (β€œPOSIX.1”) pthread(3) functionality. so like, the posix girlies are standing on her shoulders, iykyk πŸ’…


and that's the whole page bestie!! this one shipped from Debian on June 1, 2016 β€” yeah she's an oldie but a goodie, and she's still out here holding up your threads. slay, queen. go call pthread_exit(3) like a normal person tho πŸŽ€βœ¨πŸ¦‹πŸ’–

πŸ“¦ where this page comes from