pthread_once(3)
๐ pthread_once(3) ๐
okay bestie, welcome to the Library Functions Manual page for pthread_once โ yes this is a section 3 man page and yes it's about to be your new fave ๐
โจ NAME โจ
pthread_once โ once-only initialization
like... it literally does the thing one time only. that's the whole vibe. no cap.
๐ธ SYNOPSIS ๐ธ
#include <pthread.h>
pthread_once_t once_control = PTHREAD_ONCE_INIT;
int pthread_once(pthread_once_t *once_control, typeof(void (void))
*init_routine;
yes bestie the synopsis really looks like that, i didn't touch it, i promise ๐ซถ
๐ฆ DESCRIPTION ๐ฆ
okay so the whole point of pthread_once() is to make sure that a lil piece of initialization code runs at most once. at most. not twice, not "oops i did it again", once. ๐
The once_control argument points to a static or extern variable that's statically initialized to PTHREAD_ONCE_INIT. that's your little flag, your little bookmark, your little "already did this" sticker โจ
The first time pthread_once() gets called with a given once_control argument, it calls init_routine with no argument and changes the value of the once_control variable to record that initialization has been performed. so it does the thing and then it writes down that it did the thing. main character behavior, honestly.
Subsequent calls to pthread_once() with the same once_control argument do nothing. nothing!! it's giving "i said what i said" ๐ zero drama, zero re-runs.
fr fr this is the entire trick: one pointer, one init function, one guaranteed single execution. periodt.
๐ RETURN VALUE ๐
pthread_once() always returns 0.
always. like, that's it. that's the return value. iconic, no notes ๐
๐ ERRORS ๐
None.
not a single one. she doesn't miss. ๐
๐ little sign-off ๐
this page came to you from Linux man-pages 6.20, dated 2025-05-17 โ and that's the whole pthread_once(3) moment. go initialize something exactly once, bestie. i'm obsessed ๐ฆโจ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms