Bug 302600

Summary: Fix main thread initialization when disabling WebThread
Product: WebKit Reporter: David Kilzer (:ddkilzer) <ddkilzer>
Component: WebCore Misc.Assignee: David Kilzer (:ddkilzer) <ddkilzer>
Status: RESOLVED FIXED    
Severity: Normal CC: webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 176812    
Bug Blocks:    

David Kilzer (:ddkilzer)
Reported 2025-11-16 15:14:52 PST
Fix main thread initialization when disabling WebThread. When WebThread is enabled, WebCore::initializeMainThreadIfNeeded() (via +[WebView initialize]) returns early because WebCore::StartWebThread() performs "main" thread initialization when the WebThread starts. When WebThread is disabled, WebCore::initializeMainThreadIfNeeded() no longer returns early, which means main thread initialization may now incorrectly occur on a background thread if +[WebView initialize] is called from there. We must avoid this issue in WebCore::initializeMainThreadIfNeeded() by only initializing the main thread if pthread_main_np() is true, else schedule main thread initialization asynchronously on the main thread (a best-effort) using CFRunLoopPerformBlock(). We can't use synchronous main thread initialization (for example, using a semaphore) in case an app is using their own locking mechanism to initialize WebView on a background thread from the main thread.
Attachments
Radar WebKit Bug Importer
Comment 1 2025-11-16 15:15:14 PST
David Kilzer (:ddkilzer)
Comment 2 2025-11-16 15:34:13 PST
EWS
Comment 3 2025-11-16 19:54:50 PST
Committed 303102@main (f89bce6a688c): <https://commits.webkit.org/303102@main> Reviewed commits have been landed. Closing PR #54015 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.