bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: data structures for use in signal handlers


From: Bruno Haible
Subject: Re: data structures for use in signal handlers
Date: Wed, 10 Feb 2021 03:06:50 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; )

Eric Wong wrote:
> > How would setting up a pipe or eventfd help with a communication
> > problem between threads in the same process? I thought these were
> > for communication between processes.
> 
> The "self-pipe trick" is a common idiom in Unix for signal
> handling; especially when pselect/ppoll aren't available.
> I seem to recall learning of it reading something by djb.
> 
> It's perfectly valid to use pipes in single-threaded or
> multi-threaded, or multi-process situations.  POSIX gives
> well-defined semantics w.r.t. atomicity.

Atomicity alone is not an argument; the compiler and OS have
sufficient primitives (CAS instructions, barriers, spin-locks, locks)
to make things atomic between threads.

What I understand from [1] is that if a program uses signals AND
select()/poll(), then it is useful to map signals into events that
can be received by select()/poll(). The self-pipe trick is a way
to do that.

Maybe I didn't describe accurately the situation I am asking for.
I'm not attempting to transform a program to an event-based engine.
I'm looking to let signal handlers (SIGTERM, SIGSEGV, SIGWINCH, etc.)
read and traverse data structures that the main program has prepared
(and that contain information about files to delete, memory areas,
window lines to redraw etc.).

Bruno

[1] http://osiris.978.org/~alex/safesignalhandling.html




reply via email to

[Prev in Thread] Current Thread [Next in Thread]