News for hackers. Stuff that matters.
Re:Cooperative Threading by gpderetta on Wednesday November 13, 2019 @06:21AM (#21522937)
unfortunately set/swapcontext and friends require a system call to change the signal mask. So in practice they are a few orders of magnitude slower than setjump or similar.
Re:Cooperative Threading by jlokier on Wednesday November 13, 2019 @12:32PM (#21526850)
On some systems setjmp/longjmp also change the signal mask, and are just as slow. For those there is _setjmp/_longjmp.

The Linux man page explains excellently:

"POSIX does not specify whether setjmp() will save the signal mask (to be later restored during longjmp()). In System V it will not. In 4.3BSD it will, and there is a function _setjmp() that will not. The behavior under Linux depends on the glibc version and the setting of feature test macros. On Linux with glibc versions before 2.19, setjmp() follows the System V behavior by default, but the BSD behavior is provided if the _BSD_SOURCE feature test macro is explicitly defined and none of _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE, _GNU_SOURCE, or _SVID_SOURCE is defined."

Re:Cooperative Threading by loeg on Wednesday November 13, 2019 @05:13PM (#21530216)
You could easily imagine that most or all signal masks in spome green threaded program are the same, and a cheap userspace implementation of set/swapcontext that only calls into the kernel if the signal mask changes. I.e., it doesn't have to be a kernel call most of the time.