On Tue, Sep 2, 2008 at 9:39 PM, Rik van Riel <riel@xxxxxxxxxxx> wrote:
>> I am happy :)
On Tue, 2 Sep 2008 11:40:59 +0530
"Venky Shankar" <vshankar0@xxxxxxxxx> wrote:
> up(&semaphore);
> ---
> ---
> ---
> prepare_to_wait(queue, &wait, TASK_INTERRUPTIBLE);
> if(condition())
> schedule();
> finish_wait(queue, &wait);
> ---
> ---
> ---
> down_interruptible(&semaphore);
> 1. The above code can get preempted just after the call toThis is correct.
> prepare_to_wait(), In that case it would not be run again by the scheduler
> since it
> is in the TASK_INTERRUPTIBLE state. After that when someone wake's it up,
> then the check is made (if condition) and then the normal flow of code.
The task continues to run after it has set its state to TASK_INTERRUPTIBLE.
> 2. If the code does not get preempted after the call to prepare_to_wait(),
> it will still execute the if condition while in TASK_INTERRUPTIBLE state -->
> but a TASK_INTERRUPTIBLE state is not runnable - i feel this is valid after
> the call to schedule() is made. (i.e. it would not run again after it has
> given up the CPU)
Once it enters schedule() it will be taken off the runqueue and stop
being runnable.
This is ok, because by now it is on a wait queue and eventually it
should get woken up.
>> Thank you very much.
So yes, you understand this code correctly :)
>> I am happy :)
--
All rights reversed.