[TUHS] fork
G. Branden Robinson via TUHS
tuhs at tuhs.org
Fri May 15 06:30:21 AEST 2026
At 2026-05-13T07:29:15-0400, Dan Cross via TUHS wrote:
> Btw, a fun trick to turn a signal into a synchronous event, is what is
> sometimes called the, "self-pipe" trick. Here, you create a pipe, set
> the write-end of it to be non-blocking, and in your signal handler,
> write a byte into the pipe (you make it non-blocking so that you never
> block in the signal handler, should the pipe fill up). Then, you can
> run `select` (or `poll` or whatever) in your "main loop" and add the
> read-end of the pipe to the read-set you're selecting on; when you
> receive a signal, that pipe will become readable, you read a byte out
> of it, and you can do whatever you would have needed to do to handle
> the signal in a normal context. I think Dan Bernstein was the first
> person to document the idea.
Forgive the Unfrozen Caveman Engineer question, but...
How is that method superior to having a `volatile sig_atomic_t` of
Boolean sense that gets set in the signal handler and checked in the
main program's event loop? I fear I may owe some former junior
colleagues an apology...
Is Bernstein's method the preferred idiom in Plan 9, which discarded
`register`, `const`, _and_ `volatile` from its C compiler? :-O
https://plan9.io/sys/doc/comp.html
(And yeah, I know you know exactly where that document came to my
attention recently. ;-) )
Regards,
Branden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://www.tuhs.org/pipermail/tuhs/attachments/20260514/b05eb35f/attachment.sig>
More information about the TUHS
mailing list