On Wed, 13 Nov 2019 14:52:32 +0100 Victor Stinner <vstin...@python.org> wrote: > > #define _PyRuntimeState_GetThreadState(runtime) \ > > ((PyThreadState*)_Py_atomic_load_relaxed(&(runtime)->gilstate.tstate_current)) > #define _PyThreadState_GET() _PyRuntimeState_GetThreadState(&_PyRuntime) > > _PyThreadState_GET() uses "_Py_atomic_load_relaxed". I'm not used to > C99 atomic conventions. The "memory_order_relaxed" documentation says: > > "Relaxed operation: there are no synchronization or ordering > constraints imposed on other reads or writes, only this operation's > atomicity is guaranteed (see Relaxed ordering below)" > > Note: I'm not even sure why Python currently uses an atomic operation.
Is it protected by a lock? If not, you need to use an atomic. Since it's theoretically possible to read the current thread state without the GIL held (though not very useful), then an atomic is required. 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/7VL3QKACQLDL3QCWKCTUHUCIERFNE6R7/ Code of Conduct: http://python.org/psf/codeofconduct/