[Tim] > ... I believe Mark Hammond has a general set of C++ > classes to help with this stuff on Windows, but IIRC > they rely on Windows-specific TLS (thread local > storage) gimmicks. [Gordon McMillan] > No TLS. Mark's stuff actually relies on being > called (at some point) with the GIL so he can > grab the interpreter- and thread-states. Yes TLS, and all over the place. Look at the code for any of PyWinThreadState_Ensure, PyWinInterpreterLock_Acquire, PyWinInterpreterLock_Release, PyWinThreadState_Free, PyWinThreadState_Clear or DLLMAIN. TLS is used to remember what a thread's PyThreadState is, and to determine whether a thread already has a PyThreadState (it does iff the TLS slot at dwTlsIndex is non-NULL). Simple example: // Asuming we have a valid thread state, acquire the Python lock. void PyWinInterpreterLock_Acquire() { ThreadData *pData = (ThreadData *)TlsGetValue(dwTlsIndex); PyThreadState *thisThreadState = pData->ts; PyEval_AcquireThread(thisThreadState); }
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4