Chris Angelico [mailto:[email protected]]:
> And by that logic, globals are even more capable. I don't understand your
> point. Isn't the purpose of the tstate parameters to avoid the problem of
> being unable to have multiple tstates within the same OS thread? I think I've
> missed something here.
The point is that because threads can't preempt themselves, this:
/*1*/
{
Py_something(other_tstate);
}
and this:
/*2*/
{
PyInterpreterState* old_tstate = tstate;
tstate = other_state;
Py_something();
tstate = old_tstate;
}
is effectively equivalent, provided tstate is thread-local. Both will work
equally well from the hypothetical C callback that wants to use a different
subinterpreter.
That wouldn't be true if tstate was process-wide, because that would be a race
condition, some other thread might change tstate. But if tstate is
thread-local, there's no race condition.
Obviously /*1*/ is cleaner code than /*2*/, but /*2*/ is perfectly sound all
the same.
regards, Anders
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/NAD6DEOU2EYLBKOK3QACSP3MUMJ4NTOH/
Code of Conduct: http://python.org/psf/codeofconduct/