New submission from STINNER Victor:

Python 3.5 now requires a monotonic clock to start and has the C function 
_PyTime_monotonic().

Python/condvar.h and Python/thread_pthread.h should use the monotonic clock 
CLOCK_MONOTONIC, not the system clock CLOCK_REALTIME. See the PEP 418 for the 
rationale.

Most platforms support pthread_condattr_setclock(CLOCK_MONOTONIC), except Mac 
OS X and old versions of Android.

The glib looks to use pthread_cond_timedwait_relative_np() for Mac OS X:
https://mail.gnome.org/archives/commits-list/2014-February/msg07782.html

Note: Android had non-standard pthread_cond_timedwait_monotonic() and 
pthread_cond_timedwait_monotonic_np() functions. Android is not a official 
supported platform, and newer Android version now support 
pthread_condattr_setclock(). I prefer to not support old Android versions (yet).
https://android-review.googlesource.com/#/c/83881/

--

For Windows, SleepConditionVariableSRW() is used on Windows 7 and newer, 
otherwise WaitForSingleObjectEx() is used. By the way, the check looks to be 
done during the compilation. I should check which Windows version is used to 
build Python...

SleepConditionVariableSRW() and WaitForSingleObjectEx() both take a relative 
timeout, so they don't use (directly) the system clock. I don't see any 
required change for Windows.

According to the PEP 418: "WaitForSingleObject() uses the same timer as 
GetTickCount() with the same precision."

Hum, it is not possible to interrupt such wait() with CTRL+c? time.sleep() is 
implemented with WaitForSingleObjectEx() with _PyOS_SigintEvent(). It doesn't 
look to be the case here.

----------
components: Interpreter Core
messages: 235637
nosy: haypo
priority: normal
severity: normal
status: open
title: Use the monotonic clock for thread conditions on POSIX platforms
versions: Python 3.5

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

Reply via email to