Eryk Sun <eryk...@gmail.com> added the comment:

>> Try changing EnterNonRecursiveMutex() to break out of the loop in 
>> this case
>
> This does work, but unfortunately a little too well - in a single 
> test I saw several instances where that approach returned 
> _earlier_ than the timeout.

It's documented that a timeout between N and N+1 ticks can be satisfied 
anywhere in that range. In practice I see a wider range. In the kernel, 
variations in wait time could depend on when the due time is calculated in the 
interrupt cycle, when the next interrupt occurs and the interrupt time is 
updated, and when the thread is dispatched. A benefit of using a 
high-resolution external deadline is that waiting will never return early, but 
it may return later than it otherwise would, e.g. if re-waiting for a remaining 
1 ms actually takes 20 ms.

There are many unrelated WaitForSingleObject and WaitForMultipleObjects in the 
interpreter, extension modules, and code that uses _winapi.WaitForSingleObject 
and _winapi.WaitForMultipleObjects. For example, time.sleep() allows 
WAIT_TIMEOUT to override the deadline. I suggest measuring the 
performance-counter interval for time.sleep(0.001) on both the main thread 
(Sleep based) and a new thread (WaitForSingleObjectEx based).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44328>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to