On 2019-05-03, Eric V. Smith wrote:
The problem is: where would the accessor function get the state? A global variable or TLS. So you haven’t solved the problem.
What specifically is the problem with using TLS? Is it only due to performance? I recall that Dino Viehland mentioned that things can be done to make using TLS faster. This is out of my depth but it seems like the overhead should be fairly small. For a language like Python, maybe that overhead is small enough that we don't want to go through the pain of explicitly passing context.
TLS mechanisms are platform specific. Based on a tiny bit of reading, on Linux x86-64, the thread local region is stored in the GS CPU register. That would be really low overhead.
Looking at current CPython, I see this:
#define _PyThreadState_GET()
((PyThreadState*)_Py_atomic_load_relaxed(&_PyRuntime.gilstate.tstate_current))
So it would seem that Python doesn't use the optimized TLS as provided by the plaform ABI.
Regards,
Neil