<rdar://problem/6467376> Race condition in WTF::currentThread can lead to a thread...
authormrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 28 Dec 2008 02:54:12 +0000 (02:54 +0000)
committermrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 28 Dec 2008 02:54:12 +0000 (02:54 +0000)
commit1efede1660d87df2012f523dcb8da3aa1e4e80ce
tree1a135901965fad2180a7f03ded880f40bc6782bf
parenta1d010cfe3f375c94d59d3d3a7ee000bf6273892
<rdar://problem/6467376> Race condition in WTF::currentThread can lead to a thread using two different identifiers during its lifetime

If a newly-created thread calls WTF::currentThread() before WTF::createThread calls establishIdentifierForPthreadHandle
then more than one identifier will be used for the same thread.  We can avoid this by adding some extra synchronization
during thread creation that delays the execution of the thread function until the thread identifier has been set up, and
an assertion to catch this problem should it reappear in the future.

Reviewed by Alexey Proskuryakov.

* wtf/Threading.cpp: Added.
(WTF::NewThreadContext::NewThreadContext):
(WTF::threadEntryPoint):
(WTF::createThread): Add cross-platform createThread function that delays the execution of the thread function until
after the thread identifier has been set up.
* wtf/Threading.h:
* wtf/ThreadingGtk.cpp:
(WTF::establishIdentifierForThread):
(WTF::createThreadInternal):
* wtf/ThreadingNone.cpp:
(WTF::createThreadInternal):
* wtf/ThreadingPthreads.cpp:
(WTF::establishIdentifierForPthreadHandle):
(WTF::createThreadInternal):
* wtf/ThreadingQt.cpp:
(WTF::identifierByQthreadHandle):
(WTF::establishIdentifierForThread):
(WTF::createThreadInternal):
* wtf/ThreadingWin.cpp:
(WTF::storeThreadHandleByIdentifier):
(WTF::createThreadInternal):

Add Threading.cpp to the build.

* GNUmakefile.am:
* JavaScriptCore.pri:
* JavaScriptCore.scons:
* JavaScriptCore.vcproj/WTF/WTF.vcproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* JavaScriptCoreSources.bkl:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@39487 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
JavaScriptCore/ChangeLog
JavaScriptCore/GNUmakefile.am
JavaScriptCore/JavaScriptCore.pri
JavaScriptCore/JavaScriptCore.scons
JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj
JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
JavaScriptCore/JavaScriptCoreSources.bkl
JavaScriptCore/wtf/Threading.cpp [new file with mode: 0644]
JavaScriptCore/wtf/Threading.h
JavaScriptCore/wtf/ThreadingGtk.cpp
JavaScriptCore/wtf/ThreadingNone.cpp
JavaScriptCore/wtf/ThreadingPthreads.cpp
JavaScriptCore/wtf/ThreadingQt.cpp
JavaScriptCore/wtf/ThreadingWin.cpp