Bug 64465

Summary: Possible race condition in ThreadIdentifierData::initializeKeyOnce and shouldCallRealDebugger.
Product: WebKit Reporter: David Levin <levin>
Component: Web Template FrameworkAssignee: David Levin <levin>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, dimich, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: All   
Attachments:
Description Flags
Patch none

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.