NEW 114826
ThreadCondition::timedWait should use monotonicallyIncreasingTime
https://bugs.webkit.org/show_bug.cgi?id=114826
Summary ThreadCondition::timedWait should use monotonicallyIncreasingTime
Joe Mason
Reported 2013-04-18 13:20:59 PDT
Both the pthreads and Windows implementations of ThreadCondition::timedWait use the realtime clock (ie. time returned by currentTime) for their timeout. That means that if the system time changes while timedWait is running, the condition will time out at the wrong time. (For example if the clock is set to after the target time, the condition will time out immediately; if it is set forward by an hour, the condition will not time out until it reaches the original target time, which is now more than an hour in the future.) Interval measurements such as timedWait should be based on the monotonic clock (ie. time returned by monotonicallyIncreasingTime). That means that the semantics of the absoluteTime parameter would change to take a monotonically increasing value, this change must be reflected in all callers (such as BinarySemaphore::wait and MessageQueue::waitForMessageFilteredWithTimeout), and ultimately the absoluteTime passed to each of these functions must come from a call to monotonicallyIncreasingTime() +- an offset.
Attachments
wip patch (9.74 KB, patch)
2013-04-18 15:05 PDT, Joe Mason
no flags
Joe Mason
Comment 1 2013-04-18 15:05:40 PDT
Created attachment 198769 [details] wip patch The attached patch shows the scale of the changes needed. It changes the name of all functions and variables which are still type "double" but now take a monotonic time instead of currenTime, so that the compiler can catch every reference to them and the patch shows every function affected. (Obviously this rename isn't intended to be committed, but we might consider changing monotonicallyIncreasingTime to return a different type than currentTime so that the type of time measurement in each "double" isn't ambiguous.) The main thing missing from this patch is dealing with errors in the pthread_condattr_t setup (including handling platforms where CLOCK_MONOTONIC isn't available, if there are any.) And I haven't tested this at all, just checked that it compiles. But it can be a starting point for someone else to continue.
Note You need to log in before you can comment on or make changes to this bug.