• Vinson Lee's avatar
    os: Check for spurious wakeups in pipe_barrier_wait. · 31db310b
    Vinson Lee authored
    The POSIX function pthread_cond_wait can have spurious wakeups when
    waiting on a condition variable.
    
    Add a 64-bit counter that is incremented whenever the barrier becomes
    full. A woken thread checks the counter. If the counter has not changed
    then it has been spuriously woken and goes back to sleep. If the counter
    has changed then it was properly signaled and exits the barrier.
    
    Tested on Mac OS X.
    
    This patch was based on ideas from Luca Barbieri.
    31db310b
os_thread.h 10.5 KB