3 ms·
That's really interesting, I hadn't considered the case of the compiler caching the address of errno. Obviously it can't cache the value across a function call
by OskarS 4y ago
That's really interesting, I hadn't considered the case of the compiler caching the address of errno. Obviously it can't cache the value across a function call (with or without a yield point), but caching the address does make sense, and I see how that would blow up if the coroutine was scheduled on a different thread.
I'd argue that the problem here is that you should obviously not use TLS with corutines, since they can be scheduled on any thread. The concept of thread-local storage just doesn't make much sense for coroutines. The issue isn't necessarily that there's anything wrong with coroutines, it's rather with APIs that use TLS as an information side-channel. errno is just a bad idea, basically.
But point taken.
- bonzini 4y agoUsing TLS in coroutines may not make much sense, but using TLS in the runtime can be unavoidable. For example, the stack of running coroutines is per-thread. You can perhaps avoid that with a more complex API, but placing it in TLS is the obvious design. Unfortunately, this has happened and is not hypothetical, but at least for now we're stuck in the stackful hole we dug for ourselves. :( A few years back we had similar issues on Windows.