Bug 64465 - Possible race condition in ThreadIdentifierData::initializeKeyOnce and shouldCallRealDebugger.
Summary: Possible race condition in ThreadIdentifierData::initializeKeyOnce and should...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Macintosh All
: P2 Normal
Assignee: David Levin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-13 10:41 PDT by David Levin
Modified: 2011-07-13 12:19 PDT (History)
3 users (show)

See Also:


Attachments
Patch (3.97 KB, patch)
2011-07-13 11:03 PDT, David Levin
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Levin 2011-07-13 10:41:57 PDT
The race condition is highly unlikely and was only noticed through code inspection but it is trivial to make the code correct.

The race would happen if the static initialization starts to happen on two threads. 
Thread 1 does the initialization and Thread 2 is at the initialization code but hasn't yet executed it. 
Thread 1 finishes the pthread_once call and then Thread 2 initializes onceControl to PTHREAD_ONCE_INIT.
Thread 2 does the pthread_once call which happens again now.
Comment 1 David Levin 2011-07-13 10:52:20 PDT
All other instances do this correctly now.

Source/JavaScriptCore/runtime/JSLock.cpp:pthread_once_t createJSLockCountOnce = PTHREAD_ONCE_INIT;
Source/JavaScriptCore/wtf/FastMalloc.cpp:static pthread_once_t isForbiddenKeyOnce = PTHREAD_ONCE_INIT;
Source/JavaScriptCore/wtf/MainThread.cpp:static pthread_once_t initializeMainThreadKeyOnce = PTHREAD_ONCE_INIT;
Source/JavaScriptCore/wtf/ThreadIdentifierDataPthreads.cpp:static pthread_once_t onceControl = PTHREAD_ONCE_INIT;
Source/JavaScriptGlue/JSUtils.cpp:static pthread_once_t globalObjectKeyOnce = PTHREAD_ONCE_INIT;
Source/WebCore/bridge/jni/jni_jsobject.mm:static pthread_once_t javaScriptAccessLockOnce = PTHREAD_ONCE_INIT;
Source/WebKit/mac/Misc/WebKitErrors.m:static pthread_once_t registerErrorsControl = PTHREAD_ONCE_INIT;
Source/WebKit/mac/Misc/WebKitSystemBits.m:static pthread_once_t initControl = PTHREAD_ONCE_INIT;
Source/WebKit/mac/Misc/WebNSURLExtras.mm:static pthread_once_t IDNScriptWhiteListFileRead = PTHREAD_ONCE_INIT;
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebErrorsMac.mm:static pthread_once_t registerErrorsControl = PTHREAD_ONCE_INIT;
Comment 2 David Levin 2011-07-13 11:03:31 PDT
Created attachment 100687 [details]
Patch
Comment 3 Dmitry Titov 2011-07-13 11:43:12 PDT
Comment on attachment 100687 [details]
Patch

Nice.
Comment 4 WebKit Review Bot 2011-07-13 12:19:38 PDT
Comment on attachment 100687 [details]
Patch

Clearing flags on attachment: 100687

Committed r90939: <http://trac.webkit.org/changeset/90939>
Comment 5 WebKit Review Bot 2011-07-13 12:19:42 PDT
All reviewed patches have been landed.  Closing bug.