[lkml]   [2006]   [Aug]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: [KJ] [patch] fix common mistake in polling loops

    > >> Well, whoever wrote thi has some serious problems (in attitude
    > >> department). *Any* loop you design may take half a minute under
    > >> streange circumstances.
    > 6.
    > common mistake in polling loops [from Linus]:

    Yes, Linus was wrong here. Or more precisely, he's right original code
    is broken, but his suggested "fix" is worse than the original.

    unsigned long timeout = jiffies + HZ/2;
    for (;;) {
    if (ready())
    return 0;
    if (time_after(timeout, jiffies))


    > >Actually it may be broken, depending on use. In some cases this loop
    > >may want to poll the hardware 50 times, 10msec appart... and your loop
    > >can poll it only once in extreme conditions.
    > >
    > >Actually your loop is totally broken, and may poll only once (without
    > >any delay) and then directly timeout :-P -- that will break _any_
    > >user.
    > The Idea is that we are checking some event in external hardware that
    > we know will complete in a given time (This time is not dependant on
    > system activity but is fixed). After that time if the event has not
    > happened we know something has borked.

    But you have to make sure YOU CHECK READY AFTER THE TIMEOUT. Linus'
    code does not do that.
    (cesky, pictures)
    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-08-08 01:37    [W:0.021 / U:7.884 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site