3 ms·
You can longjmp from signal handlers as it's async-signal-safe in POSIX. I've done this to implement sigtimedwait on macOS and OpenBSD. If you thought writing e
by wahern 6y ago
You can longjmp from signal handlers as it's async-signal-safe in POSIX. I've done this to implement sigtimedwait on macOS and OpenBSD. If you thought writing exception-safe C++ was difficult, imagine writing async-signal-safe C++ code.
You can even longjmp across different stacks entirely. Many userspace threading libraries do this, but I've done it (legitimately, I might add) simply from a signal handler invoked on an alternate stack (see sigaltstack(2)). From the perspective of setjmp/longjmp, there isn't necessarily anything "above" the current frame. In general, longjmp is much more like a bare goto than a structured control flow construct. Notably, C++ doesn't try to make goto play nice with constructors and destructors.
Rust can do w'ever it wants because 1) it has no standard, 2) refuses to commit to an ABI of its own, and 3) there's only a single implementation, which also coincidentally 4) shares most of its toolchain with one of the most widely used C++ compilers.