Skip to content

Comment on Zig’s Io.Threaded is neatparent

Comments

how do they handle that malloc aint async signal safe?

You don’t have to do any significant work within the signal handler itself. In fact, the signal handler can literally be empty. What matters is that as long as SA_RESTART is not set, after the signal handler runs, the interrupted syscall fails with errno set to EINTR. Then the code that did the syscall can check whether a cancellation occurred (and retry the syscall if not).

Disclaimer: I haven’t looked at Zig’s implementation; I’m only going off how the Unix APIs work.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.