Re: [QUESTION] How to use interruptible_sleep_on() without races ?

Alan Cox (alan@lxorguk.ukuu.org.uk)
Fri, 5 Apr 2002 04:20:04 +0100 (BST)


> if(my_condition == TRUE)
> interruptible_sleep_on(&my_wait_queue);
> ----------------------------------
>
> Then, at some point, a timer/BH/soft-irq will do :
> -------------------------------
> my_condition == FALSE;
> wake_up_interruptible(&my_wait_queue);
>
> I looked at it in every possible way, and I don't see how it
> is possible to use safely interruptible_sleep_on(). And I wonder :

It isnt for interrupt stuff - its going back to the old kernel behaviour
when it used to be usable

> interruptible_sleep_on() but use some complex code around schedule()
> (and there must be a simpler and cleaner solution for such a simple
> problem).

Actually the code it uses is clean, slightly verbose but clean. It puts
the phases in the right order and that fixes the race cleanly. You
could just use completions in that case or you could use

wait_event_interruptible(&my_wait_queue, my_condition==FALSE)

which is a macro that generates the right stuff.

Alan
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/