[lkml]   [2001]   [Jan]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    On Mon, Jan 29, 2001 at 11:01:31AM -0600, Timur Tabi wrote:
    > What makes it more frustrating is that some people on this list talk as if
    > things things are common knowledge. I've been following this mailing list for
    > months, and until today I had no idea sleep_on was bad. All the documentation
    > I've read to date freely uses sleep_on in the sample code. In fact, I still

    When Linux documentation uses sleep_on it is probably broken and should be
    fixed. Unix (not linux) documentation uses sleep_on commonly, but Unix has
    different wait queue semantics and it is usually safe there.

    You're probably reading the wrong documentation, e.g. Rusty's
    kernel hacking HOWTO describes it correctly (and a lot of the other rules)

    > don't even know WHY it's bad. Not only that, but what am I supposed to use
    > instead?

    You can miss wakeups. The standard pattern is:

    get locks

    add_wait_queue(&waitqueue, &wait);
    for (;;) {
    if (condition you're waiting for is true)
    unlock any non sleeping locks you need for condition
    __set_task_state(current, TASK_UNINTERRUPTIBLE);
    __set_task_state(current, TASK_RUNNING);
    reaquire locks
    remove_wait_queue(&waitqueue, &wait);

    When you want to handle signals you can check for them before or after the
    condition check. Also use TASK_INTERRUPTIBLE in this case.

    When you need a timeout use schedule_timeout().

    For some cases you can also use the wait_event_* macros which encapsulate
    that for you, assuming condition can be tested/used lockless.

    An alternative is to use a semaphore, although that behaves a bit differently
    under load.

    > This is what I find most frustrating about Linux. If I were a Windows driver
    > programmer, I could walk into any bookstore and pick up any of a dozen books
    > that explains everything, leaving no room for doubt.

    Just why are Windows drivers so buggy then?

    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 13:25    [W:0.020 / U:7.728 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site