Bug 22360
Summary: | WTF current time code uses unprotected static variables | ||
---|---|---|---|
Product: | WebKit | Reporter: | Alexey Proskuryakov <ap> |
Component: | Web Template Framework | Assignee: | Nobody <webkit-unassigned> |
Status: | NEW | ||
Severity: | Normal | CC: | barraclough, darin, kevinwatters, sfalken |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | All | ||
OS: | All |
Alexey Proskuryakov
Recently, a number of static variables were added to JSC::getCurrentUTCTimeWithMicroseconds(). These include doubles, which are not written to memory atomically on common platforms. Likely, this also created race conditions in this function, although I don't have any to pinpoint.
I'm fairly sure that this will make JavaScriptCore date/time functions misbehave when used from multiple concurrent threads.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Darin Adler
Since this is Windows-specific code, we can just use Windows thread-specific globals for this. Should be very quick to fix that way.
Darin Adler
I mean __declspec(thread).
Darin Adler
Steve mentioned that __declspec(thread) doesn't work for delay-loaded libraries (at least on XP) so we probably need to stay away from it.
Darin Adler
Generally speaking, for our uses it seems fine for each thread to have its own separate "drift-free" mechanism, so we don't need to introduce locking here -- per-thread data should suffice.
I'm contemplating adding JSGlobalData* arguments into these calls and moving the data there.
Alexey Proskuryakov
Someone just mentioned on IRC that they wanted to move this function to WTF, in order to replace gettimeofday in ThreadingPthreads (I don't know why exactly).
Kevin Watters
(In reply to comment #5)
> Someone just mentioned on IRC that they wanted to move this function to WTF, in
> order to replace gettimeofday in ThreadingPthreads (I don't know why exactly).
>
The reason is that the wx port is switching from ThreadingNone.cpp to ThreadingPthreads.cpp, in which the ThreadCondition::timedWait function needs a high resolution timer to calculate a target time to give to pthread_cond_timedwait.
My temporary solution was to implement gettimeofday in that file using the Win32 function GetSystemTimeAsFileTime--but reusing getCurrentUTCTimeWithMicroseconds would work as well if it makes sense to have some time functionality in WTF.
Gavin Barraclough
Naturally aligned memory accesses are atomic on X86, so if this is windows specific code, it this an issue?
Alexey, I can't find a method called getCurrentUTCTimeWithMicroseconds - do you know if this has been renamed?
cheers,
G.
Darin Adler
It’s the currentTime() functions in CurrentTime.cpp.
Alexey Proskuryakov
> Naturally aligned memory accesses are atomic on X86
I didn't know that double accesses were also atomic. I believe x86 also has some guarantees for in-order writes, but code like below still makes me nervous:
static bool init = false;
static double lastTime;
static DWORD lastTickCount;
if (!init) {
// ..
}
On most platforms, monotonicallyIncreasingTime() has a whole static mach_timebase_info_data_t variable, e.g.
static mach_timebase_info_data_t timebaseInfo;
if (!timebaseInfo.denom) {
Alexey Proskuryakov
> On most platforms
s/most platforms/the Mac/