![](https://secure.gravatar.com/avatar/1fee087d7a1ca17c8ad348271819a8d5.jpg?s=120&d=mm&r=g)
On Fri, 29 Jan 2021 18:15:37 +0100 Victor Stinner <vstinner@python.org> wrote:
Hi Mark,
I tried to use C11 _Thread_local (Thread Local Storage, TLS) only with GCC and clang and I got issues on macOS: https://github.com/python/cpython/pull/23976
My PR uses __thread if _Thread_local is not available.
I don't think that MSC (Visual Studio) implements C11 _Thread_local, but it provides __declspec(thread). I tried it and I got issues with DLL. I didn't dig into this issue. MSC loves C++ but seems stuck at C99 (I'm not even sure if it's fully implemented).
It seems like declaring a TLS in libpython and using it from an extension module (another dynamic library) is causing issues depending on the linker. It "should" work on macOS, but it doesn't.
You can hide the access behind a function call. Slightly more costly, but shouldn't be that expensive on modern machines. Regards Antoine.