If the signals that I want to mask and unmask are common between all threads, can I use one global variable for the signal set in POSIX C to pass to pthread_sigmask, or there should be different sigsets for each thread?
The second argument of
pthread_sigmask() is constant (
const sigset_t *set) [meaning that the memory pointed by
set will not be modified], so you can declare a single [possibly global, at your opinion] variable, without the need of implementing any thread locking mechanism while accessing it as it won't be modified. All threads will always read the same [consistent] value from it.
You can declare something like:
/* Global scope */ sigset_t g_set;
And pass it to
/* Assuming `g_set` is already properly set at this point */ pthread_sigmask(how, &g_set, NULL);