Changeset 260682 in webkit
- Timestamp:
- Apr 24, 2020 4:56:38 PM (4 years ago)
- Location:
- trunk/Source
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r260679 r260682 1 2020-04-24 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [WTF] allThreads registration is racy with allThreads unregistration 4 https://bugs.webkit.org/show_bug.cgi?id=210995 5 <rdar://problem/61609690> 6 7 Reviewed by Keith Miller. 8 9 There is a race between registering a thread to allThreads and unregistering a thread from allThreads. 10 11 1. Caller: A new thread is created, but not registering it to allThreads yet. 12 2. Thread: The thread is running. 13 3. Thread: The thread finishes its execution before the thread is registered into allThreads. 14 4. Thread: The thread unregisters itself from allThreads. 15 5. Caller: Registers the new thread to allThreads after it already finished its execution. 16 6. The thread is never removed from allThreads. 17 18 This patch adds m_didUnregisterFromAllThreads flag to Thread, and add the thread to allThreads only when this flag is false. 19 20 Covered by LayoutTests/inspector/cpu-profiler/threads.html. 21 22 * wtf/Threading.cpp: 23 (WTF::Thread::create): 24 (WTF::Thread::didExit): 25 * wtf/Threading.h: 26 (WTF::Thread::Thread): 27 1 28 2020-04-24 Alex Christensen <achristensen@webkit.org> 2 29 -
trunk/Source/WTF/wtf/Threading.cpp
r257521 r260682 197 197 } 198 198 199 { 200 LockHolder lock(allThreadsMutex()); 201 allThreads(lock).add(&thread.get()); 199 // We must register threads here since threads registered in allThreads are expected to have complete thread data which can be initialized in launched thread side. 200 // However, it is also possible that the launched thread has finished its execution before it is registered in allThreads here! In this case, the thread has already 201 // called Thread::didExit to unregister itself from allThreads. Registering such a thread will register a stale thread pointer to allThreads, which will not be removed 202 // even after Thread is destroyed. Register a thread only when it has not unregistered itself from allThreads yet. 203 { 204 auto locker = holdLock(allThreadsMutex()); 205 if (!thread->m_didUnregisterFromAllThreads) 206 allThreads(locker).add(thread.ptr()); 202 207 } 203 208 … … 223 228 { 224 229 { 225 LockHolder lock(allThreadsMutex()); 226 allThreads(lock).remove(this); 230 auto locker = holdLock(allThreadsMutex()); 231 allThreads(locker).remove(this); 232 m_didUnregisterFromAllThreads = true; 227 233 } 228 234 -
trunk/Source/WTF/wtf/Threading.h
r257521 r260682 317 317 unsigned m_gcThreadType : 2; 318 318 319 bool m_didUnregisterFromAllThreads { false }; 320 319 321 // Lock & ParkingLot rely on ThreadSpecific. But Thread object can be destroyed even after ThreadSpecific things are destroyed. 320 322 // Use WordLock since WordLock does not depend on ThreadSpecific and this "Thread". -
trunk/Source/WebCore/ChangeLog
r260678 r260682 1 2020-04-24 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [WTF] allThreads registration is racy with allThreads unregistration 4 https://bugs.webkit.org/show_bug.cgi?id=210995 5 <rdar://problem/61609690> 6 7 Reviewed by Keith Miller. 8 9 * page/cocoa/ResourceUsageThreadCocoa.mm: 10 (WebCore::ResourceUsageThread::platformCollectCPUData): 11 1 12 2020-04-24 Wenson Hsieh <wenson_hsieh@apple.com> 2 13 -
trunk/Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm
r260366 r260682 157 157 HashSet<mach_port_t> knownWebKitThreads; 158 158 { 159 LockHolder lock(Thread::allThreadsMutex());160 for (auto* thread : Thread::allThreads(lock )) {159 auto locker = holdLock(Thread::allThreadsMutex()); 160 for (auto* thread : Thread::allThreads(locker)) { 161 161 mach_port_t machThread = thread->machThread(); 162 162 if (machThread != MACH_PORT_NULL)
Note: See TracChangeset
for help on using the changeset viewer.