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