+2026-04-04 Bruno Haible <bruno@clisp.org>
+
+ asyncsafe-spin: Prefer pthread_sigmask over sigprocmask.
+ Suggested by Paul Eggert.
+ * lib/asyncsafe-spin.c (asyncsafe_spin_lock, asyncsafe_spin_unlock): Use
+ pthread_sigmask instead of sigprocmask.
+ * modules/asyncsafe-spin (Depends-on): Add pthread_sigmask. Remove
+ sigprocmask.
+ (Link): New section.
+ * modules/asyncsafe-spin-tests (Makefile.am): Link test-asyncsafe-spin1
+ with $(PTHREAD_SIGMASK_LIB).
+ * modules/jit/cache-tests (Makefile.am): Link test-cache with
+ $(PTHREAD_SIGMASK_LIB).
+
2026-04-04 Bruno Haible <bruno@clisp.org>
spawn-pipe: Prefer pthread_sigmask over sigprocmask.
On platforms other than native Windows, it is useful to do the same
thing also within a signal handler, since signals may remain enabled
while a signal handler runs. It is possible to do this because
- sigprocmask() is safe to call from within a signal handler, see
+ pthread_sigmask() is safe to call from within a signal handler, see
POSIX section "Signal Actions"
<https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html#tag_16_04_03>.
- (In other words, sigprocmask() is atomic, because it is implemented as a
+ (In other words, pthread_sigmask() is atomic, because it is implemented as a
system call.)
- Whereas on native Windows, sigprocmask() is not atomic, because it
- manipulates global variables. Therefore in this case, we are *not*
- allowed to call it from within a signal handler. */
+ Whereas on native Windows, pthread_sigmask() = sigprocmask() is not atomic,
+ because it manipulates global variables. Therefore in this case, we are
+ *not* allowed to call it from within a signal handler. */
- /* FIXME: Use pthread_sigmask, not sigprocmask, as the two functions
- behave differently on macOS and the sigprocmask behavior can cause
- this thread to race with other threads in harmful ways. */
#if defined _WIN32 && !defined __CYGWIN__
if (!from_signal_handler)
#endif
- sigprocmask (SIG_BLOCK, mask, saved_mask);
+ pthread_sigmask (SIG_BLOCK, mask, saved_mask);
glthread_spinlock_lock (lock);
}
if (glthread_spinlock_unlock (lock))
abort ();
- /* FIXME: Use pthread_sigmask, not sigprocmask, as the two functions
- behave differently on macOS and the sigprocmask behavior can cause
- this thread to race with other threads in harmful ways. */
#if defined _WIN32 && !defined __CYGWIN__
if (!from_signal_handler)
#endif
- sigprocmask (SIG_SETMASK, saved_mask, NULL);
+ pthread_sigmask (SIG_SETMASK, saved_mask, NULL);
}
void