pthread_at...sigmask_np(3)
π pthread_at...sigmask_np(3) β Library Functions Manual π
okay bestie, pull up a chair, we're doing signal masks today and honestly?? it's giving main character energy. this page lives in the Library Functions Manual section, and it's all about setting and getting the signal mask attribute on a thread attributes object. no cap. π
β¨ NAME β¨
pthread_attr_setsigmask_np, pthread_attr_getsigmask_np β set/get signal mask attribute in thread attributes object
πΈ LIBRARY πΈ
POSIX threads library (libpthread, -lpthread)
don't forget to link her, she's not gonna link herself π
π¦ SYNOPSIS π¦
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <pthread.h>
int pthread_attr_setsigmask_np(pthread_attr_t *attr,
const sigset_t *sigmask);
int pthread_attr_getsigmask_np(const pthread_attr_t *attr,
sigset_t *sigmask);
π DESCRIPTION π
okay so here's the tea. β
pthread_attr_setsigmask_np() sets the signal mask attribute of the thread attributes object that attr points at β and it sets it to whatever value you dropped into *sigmask. slay. and if you pass sigmask as NULL? then any signal mask attribute that was already chilling in attr gets unset. bye babe π
pthread_attr_getsigmask_np() is the reader of the duo β it hands you back the signal mask attribute of the thread attributes object referred to by attr, and it writes it into the buffer that sigmask points at. but bestie, plot twist: if the signal mask attribute is currently unset, this function doesn't give you a mask at all β it returns the special value PTHREAD_ATTR_NO_SIGMASK_NP as its result instead. iconic behavior fr fr.
π₯ RETURN VALUE π₯
pthread_attr_setsigmask_np()β returns0on success, or a nonzero error number if it didn't go. periodt.pthread_attr_getsigmask_np()β returns either0orPTHREAD_ATTR_NO_SIGMASK_NP. when0comes back, the signal mask attribute got delivered to you throughsigmask. when you getPTHREAD_ATTR_NO_SIGMASK_NP, that's the universe telling you the signal mask attribute is not set inattr. π- on error, both of these functions return a positive error number.
π ERRORS π
ENOMEMβ only frompthread_attr_setsigmask_np(). could not allocate memory. she tried her best, the malloc said no. π
π ATTRIBUTES π
for an explanation of the terms used in this section, go peek at attributes(7).
- Interface:
pthread_attr_setsigmask_np(),pthread_attr_getsigmask_np() - Attribute: Thread safety
- Value: MT-Safe
both of them, MT-Safe, together, as a unit. π«Ά
β STANDARDS β
GNU β hence the suffix _np (nonportable) chilling in the names. iykyk. it's nonportable and it's not sorry about it.
π§ HISTORY π§
glibc 2.32.
a modern queen. born recently, already thriving.
π NOTES π
so here's the thing you actually need to know, bestie:
the signal mask attribute is the thing that decides which signal mask is gonna be assigned to a thread created using the thread attributes object attr. and if this attribute is not set? then a thread created using attr just inherits a copy of the creating thread's signal mask. inherit like a hand-me-down, cute but maybe not what you wanted. π
want more details on signal masks in general? run, don't walk, to sigprocmask(2). and for a description of a whole set of macros you can use to manipulate and inspect signal sets, see sigsetops(3). those macros ate.
and now the fun part π β if pthread_attr_setsigmask_np() didn't exist at all, you could still create a thread with the signal mask you wanted, by doing this little dance:
- The creating thread uses
pthread_sigmask(3)to save its current signal mask and set its mask to block all signals. - The new thread is then created using
pthread_create(); the new thread will inherit the creating thread's signal mask. - The new thread sets its signal mask to the desired value using
pthread_sigmask(3). - The creating thread restores its signal mask to the original value.
and why do all that, you ask? because if you follow the steps above, there is no possibility for the new thread to receive a signal before it has adjusted its signal mask to the desired value. no window, no gap, no sneaky signal slipping in before the vibe check. that's the whole point. π
πΈ SEE ALSO πΈ
sigprocmask(2), pthread_attr_init(3), pthread_sigmask(3), pthreads(7), signal(7)
and that's the page, bestie!! π¦ this one came from Linux man-pages 6.20, dated 2025-05-17 β and the page itself is pthread_at...sigmask_np(3). go forth and mask your signals responsibly. mwah πβ¨π
π¦ 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