On 2026-04-05 18:46, Bruno Haible wrote:
Hm? I don't understand. The goal being to avoid that a SIGINT signal being
handled by a thread other than the current thread, how can a spin lock help
doing that?
If you mean to install a certain SIGINT handler, how do you imagine that
handler to look like?

Well, perhaps I'm not understanding the situation correctly, but from the brief description of what fatal-error does it seems to me that it could use a static pthread_t variable T containing the identity of the thread that should handle SIGINT. If the signal handler fires off in some thread other than T, the handler merely uses pthread_kill to forward SIGINT to T.

Setters and getters of T can be protected both by blocking SIGINT (to make them async-signal-safe) and by a spin lock (to make them thread-safe). The pattern should be block, lock, do the work, unlock, unblock. If the signal is known to be already blocked (e.g., the pattern's called from a SIGINT handler established without SA_NODEFER), the pattern can skip the block and unblock steps.


Reply via email to