On Tue, 17 Mar 2020 14:47:19 +0000 Mark Shannon <m...@hotpy.org> wrote: > On 16/03/2020 3:04 pm, Victor Stinner wrote: > > Hi, > > > >> Changes on this scale merit a PEP and proper discussion, rather than > >> being added piecemeal without proper review. > > > > Last November, I asked explicitly on python-dev if we should "Pass the > > Python thread state to internal C functions": > > https://mail.python.org/archives/list/python-dev@python.org/thread/PQBGECVGVYFTVDLBYURLCXA3T7IPEHHO/#Q4IPXMQIM5YRLZLHADUGSUT4ZLXQ6MYY > > > > In short, the answer is yes. > > I said "no" then and gave reasons. AFAICT no one has faulted my reasoning. > > Let me reiterate why using a thread-local variable is better than > passing the thread state down the C stack. > > 1. Using a thread-local variable for the thread state requires much > smaller changes to the code base. > > 2. Using a thread-local variable is less error prone. When passing > tstate as a parameter, what happens if the tstate argument is from a > different thread or is NULL? Are you adding checks for those cases? > What are the performance implications of adding those checks? > > 3. Using a thread-local variable is likely to be a little bit faster. > Passing an argument down the stack increases register pressure and spills. > Accessing a thread-local is slower at the point of access, but the cost > is incurred only when it is needed, so is cheaper overall.
The problem here is if different subinterpreters create a thread state for the same OS thread. Sounds unlikely, perhaps, but not entirely, especially if that thread state is created from a foreign C library's callback. Regards Antoine. _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/7IZMNVXEJCY5RCIDIEK4CADPW7UPGSGR/ Code of Conduct: http://python.org/psf/codeofconduct/