This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author sdeibel
Recipients paul.moore, sdeibel, steve.dower, tim.golden, zach.ware
Date 2017-06-15.13:34:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1497533657.78.0.0164938560567.issue30676@psf.upfronthosting.co.za>
In-reply-to
Content
In acquire_timed in _threadmodule.c (used to implement threading lock acquire()) there is an optimization from https://github.com/python/cpython/commit/e75ff35af2b6c85d48c68b95f295aeac7396b162 that says it first tries non-blocking lock w/o releasing the GIL.  However, it seems that this call can block on Windows.

The call to PyThread_acquire_lock_timed(lock, 0, 0) (w/o releasing GIL) on Windows calls EnterNonRecursiveMutex which in turn, in the _PY_USE_CV_LOCKS impl, immediately calls PyMUTEX_LOCK as if it's not going to block.  However, various implementations of this seem like they can block.  Specifically, the impls of PyMUTEX_LOCK that end up using AcquireSRWLockExclusive and EnterCriticalSection both block.  The only case that is correct (does not block) is when !_PY_USE_CV_LOCKS where EnterNonRecursiveMutex() instead calls WaitForSingleObjectEx() with the zero timeout.

This seems like an incorrect potential for GIL deadlock, because the thread blocks without releasing GIL.  Shouldn't it ultimately be using TryAcquireSRWLockExclusive and TryEnterCriticalSection in these two cases?

This seems like an issue on Windows only.  The pthreads implementations look like they correctly handle timeout of 0 sent to PyThread_acquire_lock_timed().
History
Date User Action Args
2017-06-15 13:34:17sdeibelsetrecipients: + sdeibel, paul.moore, tim.golden, zach.ware, steve.dower
2017-06-15 13:34:17sdeibelsetmessageid: <1497533657.78.0.0164938560567.issue30676@psf.upfronthosting.co.za>
2017-06-15 13:34:17sdeibellinkissue30676 messages
2017-06-15 13:34:17sdeibelcreate