[lkml]   [2006]   [Jan]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: pthread_mutex_unlock (was Re: sched_yield() makes OpenLDAP slow)
    Howard Chu wrote:
    > Kaz's post clearly interprets the POSIX spec differently from you. The
    > policy can decide *which of the waiting threads* gets the mutex, but the
    > releasing thread is totally out of the picture. For good or bad, the
    > current pthread_mutex_unlock() is not POSIX-compliant. Now then, if
    > we're forced to live with that, for efficiency's sake, that's OK,
    > assuming that valid workarounds exist, such as inserting a sched_yield()
    > after the unlock.

    Did you read the rest of this post?

    "In any event, all the mutex fairness in the world won't solve the
    problem. Consider if this lock/unlock cycle is inside a larger
    lock/unlock cycle. Yielding at the unlock or blocking at the lock will
    increase the dreadlock over the larger mutex.

    The fact is, the threads library can't read the programmer's mind. So
    it shouldn't try to, especially if that makes the common cases much
    worse for the benefit of excruciatingly rare cases."

    And earlier in that thread ("old behavior" referring to an old
    LinuxThreads version which allowed "unfair" locking):

    "Notice however that even the old "unfair" behavior is perfectly
    acceptable with respect to the POSIX standard: for the default
    scheduling policy, POSIX makes no guarantees of fairness, such as "the
    thread waiting for the mutex for the longest time always acquires it
    first". Properly written multithreaded code avoids that kind of heavy
    contention on mutexes, and does not run into fairness problems. If you
    need scheduling guarantees, you should consider using the real-time
    scheduling policies SCHED_RR and SCHED_FIFO, which have precisely
    defined scheduling behaviors. "

    If you indeed have some thread which is trying to do an essentially
    infinite amount of work, you really should not have that thread locking
    a mutex, which other threads need to acquire, for a large part of each
    cycle. Correctness aside, this is simply not efficient.

    Robert Hancock Saskatoon, SK, Canada
    To email, remove "nospam" from
    Home Page:
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2006-01-26 01:21    [W:0.021 / U:3.848 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site