Changeset 221083 in webkit


Ignore:
Timestamp:
Aug 23, 2017 10:41:39 AM (7 years ago)
Author:
Yusuke Suzuki
Message:

Race condition in StartWebThread causing crash
https://bugs.webkit.org/show_bug.cgi?id=175852

Reviewed by Mark Lam.

When starting web thread, the main thread waits for completion of web thread initialization
by using pthread_cond_t. However, the main thread may be woken up due to the existence of
the spurious wake up of pthread_cond_t.

Instead, we should use WTF::Lock and WTF::Condition. Since our StartWebThread already calls
WTF::initializeThreading, it is safe to use WTF::Lock and WTF::Condition. And our WTF::Condition
does not have the spurious wake up problem as described in Condition.h.

  • platform/ios/wak/WebCoreThread.mm:

(RunWebThread):
(StartWebThread):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r221077 r221083  
     12017-08-23  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Race condition in StartWebThread causing crash
     4        https://bugs.webkit.org/show_bug.cgi?id=175852
     5
     6        Reviewed by Mark Lam.
     7
     8        When starting web thread, the main thread waits for completion of web thread initialization
     9        by using pthread_cond_t. However, the main thread may be woken up due to the existence of
     10        the spurious wake up of pthread_cond_t.
     11
     12        Instead, we should use WTF::Lock and WTF::Condition. Since our StartWebThread already calls
     13        WTF::initializeThreading, it is safe to use WTF::Lock and WTF::Condition. And our WTF::Condition
     14        does not have the spurious wake up problem as described in Condition.h.
     15
     16        * platform/ios/wak/WebCoreThread.mm:
     17        (RunWebThread):
     18        (StartWebThread):
     19
    1202017-08-23  Brent Fulgham  <bfulgham@apple.com>
    221
  • trunk/Source/WebCore/platform/ios/wak/WebCoreThread.mm

    r220186 r221083  
    128128static CFRunLoopObserverRef mainRunLoopAutoUnlockObserver;
    129129
    130 static pthread_mutex_t startupLock = PTHREAD_MUTEX_INITIALIZER;
    131 static pthread_cond_t startupCondition = PTHREAD_COND_INITIALIZER;
     130static StaticLock startupLock;
     131static StaticCondition startupCondition;
    132132
    133133static WebThreadContext *webThreadContext;
     
    682682    CFRunLoopAddSource(webThreadRunLoop, WebThreadReleaseSource, kCFRunLoopDefaultMode);
    683683
    684     int result = pthread_mutex_lock(&startupLock);
    685     ASSERT_WITH_MESSAGE(result == 0, "startup lock failed with code:%d", result);
    686 
    687     result = pthread_cond_signal(&startupCondition);
    688     ASSERT_WITH_MESSAGE(result == 0, "startup signal failed with code:%d", result);
    689 
    690     result = pthread_mutex_unlock(&startupLock);
    691     ASSERT_WITH_MESSAGE(result == 0, "startup unlock failed with code:%d", result);
     684    {
     685        LockHolder locker(startupLock);
     686        startupCondition.notifyOne();
     687    }
    692688
    693689    while (1)
     
    759755
    760756    // Wait for the web thread to startup completely before we continue.
    761     int result = pthread_mutex_lock(&startupLock);
    762     ASSERT_WITH_MESSAGE(result == 0, "startup lock failed with code:%d", result);
    763 
    764     // Propagate the mainThread's fenv to workers & the web thread.
    765     FloatingPointEnvironment::singleton().saveMainThreadEnvironment();
    766 
    767     pthread_create(&webThread, &tattr, RunWebThread, NULL);
    768     pthread_attr_destroy(&tattr);
    769 
    770     result = pthread_cond_wait(&startupCondition, &startupLock);
    771     ASSERT_WITH_MESSAGE(result == 0, "startup wait failed with code:%d", result);
    772 
    773     result = pthread_mutex_unlock(&startupLock);
    774     ASSERT_WITH_MESSAGE(result == 0, "startup unlock failed with code:%d", result);
     757    {
     758        LockHolder locker(startupLock);
     759
     760        // Propagate the mainThread's fenv to workers & the web thread.
     761        FloatingPointEnvironment::singleton().saveMainThreadEnvironment();
     762
     763        pthread_create(&webThread, &tattr, RunWebThread, NULL);
     764        pthread_attr_destroy(&tattr);
     765
     766        startupCondition.wait(startupLock);
     767    }
    775768
    776769    initializeApplicationUIThreadIdentifier();
Note: See TracChangeset for help on using the changeset viewer.