gh-150452: use PyMutex in socket module#150453
Conversation
|
The change is not user-facing, news isn't needed. This PR alone is sufficient, you can close the other one and I'll backport this. |
| #endif | ||
| #else /* not HAVE_GETHOSTBYNAME_R */ | ||
| #ifdef USE_GETHOSTBYNAME_LOCK | ||
| PyThread_acquire_lock(netdb_lock, 1); |
There was a problem hiding this comment.
Currently, PyThread_acquire_lock() is implemented with _PyMutex_LockTimed(lock, -1, _Py_LOCK_DONT_DETACH), whereas PyMutex_Lock() uses _PY_LOCK_DETACH. Is it ok to "Detach/release the GIL while waiting on the lock"? I think so, but I'm not sure. I'm not a PyMutex expert :-)
There was a problem hiding this comment.
I just had a look and I would say so given both call sites are within a Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS block, so as far as I know we already aren't running with the GIL held.
Is that right or am I missing something? I'm clearly not a PyMutex expert either.
Co-authored-by: Victor Stinner <vstinner@python.org>
Fixes #150452.
socketmodule should usePyMutexinstead of Lock #150452