address_of_errno = &errno;
...
foo = *address_of_errno;
The compiler can assume that the address stays the same across the whole execution of the function and cache it in a register. Unfortunately, if you can change threads across yield points, you can end up reading the errno of the wrong function.Instead, C++ stackless coroutines explicitly promise that you will read the TLS of the currently executing thread in this case.
This is what we found, but I cannot rule out that this is the only possibility.