[lkml]   [2006]   [Jan]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: pthread_mutex_unlock (was Re: sched_yield() makes OpenLDAP slow)
    On Jan 30, 2006, at 03:50, Howard Chu wrote:
    > Helge Hafting wrote:
    >> linux-os (Dick Johnson) wrote:
    >>> To fix the current problem, you can substitute usleep(0); It will
    >>> give the CPU to somebody if it's computable, then give it back to
    >>> you. It seems to work in every case that sched_yield() has mucked
    >>> up (perhaps 20 to 30 here).
    >> Isn't that dangerous? Someday, someone working on linux (or some
    >> other unixish os) might come up with an usleep implementation
    >> where usleep(0) just returns and becomes a no-op. Which probably
    >> is ok with the usleep spec - it did sleep for zero time . . .
    > We actually experimented with usleep(0) and select(...) with a
    > zeroed timeval. Both of these approaches performed worse than just
    > using sched_yield(), depending on the system and some other
    > conditions. Dual-core AMD64 vs single-CPU had quite different
    > behaviors. Also, if the slapd main event loop was using epoll()
    > instead of select(), the select's used for yields slowed down by a
    > couple orders of magnitude. (A test that normally took ~30 seconds
    > took as long as 45 minutes in one case, it was quite erratic.)
    > It turned out that most of those yield's were leftovers inherited
    > from when we only supported non-preemptive threads, and simply
    > deleting them was the best approach.

    I would argue that in a non realtime environment sched_yield() is not
    useful at all. When you want to wait for another process, you wait
    explicitly for that process using one of the various POSIX-defined
    methods, such as mutexes, condition variables, etc. There are very
    clearly and thoroughly defined ways to wait for other processes to
    complete work, why rely on usleep(0) giving CPU to some other task
    when you can explicitly tell the scheduler "I am waiting for task foo
    to release this mutex" or "I can't run until somebody signals this
    condition variable".

    Kyle Moffett

    Unix was not designed to stop people from doing stupid things,
    because that would also stop them from doing clever things.
    -- Doug Gwyn

    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-30 16:36    [W:0.022 / U:11.056 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site