Re: questions on wait_event ...

From: Alexey Shinkin
Date: Thu Dec 22 2005 - 19:50:30 EST




Alexey Shinkin wrote:
Hi , all !
Could anyone please clarify one thing in that old well known
wait_event_... code (taken from 2.6.5 wait.h ):

#define __wait_event_interruptible(wq, condition, ret) \
do { \
wait_queue_t __wait; \
init_waitqueue_entry(&__wait, current); \
\
add_wait_queue(&wq, &__wait); \
for (;;) { \
set_current_state(TASK_INTERRUPTIBLE); \
if (condition) \
break;
........................................

Is it possible that scheduling happen after set_current_state() but before
checking the condition ?
If yes - even if we will have condition==TRUE by this moment - the scheduler
will make the process to sleep anyway , right ?

Yes, but since the condition would then have changed after we were put into the wait queue, they would have woken up the queue and we should be woken up again.

--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@xxxxxxxxxxxxx
Home Page: http://www.roberthancock.com/



And what if the condition have changed after we have checked it in wait_event() but
before calling __wait_event() and before putting the process into the wait queue ?
The process could not be woken up "in advance" , right ?


#define wait_event(wq, condition) \
do { \
if (condition) \
break; \
/* and here we have condition changed ???? */
__wait_event(wq, condition); \
} while (0)


Regards
Alexey Shinkin

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! http://search.msn.com/

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