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 to > 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. This is correct. > 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) The task continues to run after it has set its state to TASK_INTERRUPTIBLE. 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. So yes, you understand this code correctly :) -- All rights reversed. -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ