• R
    internal locks: new owner of contended lock must set waiters flag · e7655ed3
    Rich Felker 提交于
    this bug probably would have gone unnoticed since it's only used in
    the fallback code for systems where priority-inheritance locking
    fails. unfortunately this approach results in one spurious wake
    syscall on the final unlock, when there are no waiters remaining. the
    alternative (possibly better) would be to use broadcast wakes instead
    of reflagging the waiter unconditionally, and let each waiter reflag
    itself; this saves one syscall at the expense of invoking the
    "thundering herd" effect (worse performance degredation) when there
    are many waiters.
    
    ideally we would be able to update all of our locks to use an array of
    two ints rather than a single int, and use a separate counter system
    like proper mutexes use; then we could avoid all spurious wake calls
    without resorting to broadcasts. however, it's not clear to me that
    priority inheritance futexes support this usage. the kernel sets the
    waiters flag for them (just like we're doing now) and i can't tell if
    it's safe to bypass the kernel when unlocking just because we know
    (from private data, the waiter count) that there are no waiters. this
    is something that could be explored in the future.
    e7655ed3
__lock.c 648 字节