[Again apologies for dupes. I really need to fix that]
On 5/3/19 2:53 PM, Neil Schemenauer wrote:
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.
I'm just saying that if passing around a parameter is the solution to not using global state or TLS, then having a parameter-less accessor function to that state doesn't solve the problem: you're still using global state or TLS.
I think global state is a non-starter, of course. I could live with TLS. I don't know its performance relative to passing a parameter to all functions.
Eric
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