Re: Problems writting a CHAR Driver with interruptible_sleep (wait_queu e)

Benjamin LaHaise (kernel@kvack.org)
Mon, 16 Aug 1999 07:49:49 -0400 (EDT)


On Sat, 14 Aug 1999, Russell King wrote:

> Benjamin LaHaise writes:
> > current->state = TASK_INTERRUPTIBLE;
> > add_wait_queue(&my_wait_queue, &wait);
>
> That should be:
> add_wait_queue(&my_wait_queue, &wait);
> current->state = TASK_INTERRUPTIBLE;
>
> otherwise there is a chance that the interrupt could occur between
> the TASK_INTERRUPTIBLE and the add_wait_queue. If this does happen,
> the task will not be on my_wait_queue, and therefore the state will
> not be set to TASK_RUNNING.

Ummm, no, that's worse and a different kind of race: you'll note that in
the original code I posted, the trigger for the wake up should be
started *after* the add_wait_queue. With your change, what happens if
someone else had already triggered the interrupt and it does a wake_up
between the add_wait_queue and current->state = TASK_INTERRUPTIBLE? The
task will then sleep until the wait queue gets another
wake_up_interruptible or a signal arrives for the task, which is wrong.

-ben

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