Re: linux sleep implementation
- From: Iwo Mergler <Iwo.Mergler@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 15 Sep 2006 17:14:19 +0100
Ask wrote:
1> sleeping in the kernel is like this (source taken from Robert Love
Book, page 53)
add_wait_queue(q, &wait);
while (!condition) {
set_current_state(TASK_INTERRUPTIBLE);
if (signal_pending(current))
...............................
schedule();
}
set_current_state(TASK_RUNNING);
remove_wait_queue(q, &wait);
Isn't it possible that just before the schedule is invoked, the task is
pre-empted. What if it is preempted because of the event that it
intends to wait for occurs. Will it give weird result in that case ?
It can be preempted. The effect is the same as if schedule was called.
When the signal is delivered, the task changes back to TASK_RUNNING.
I vaguely remember the above code to be a workaround to avoid a race
condition when using a 2.4.x kernel. Newer kernels have a call which
allows you to go to sleep and check your condition atomically.
2> What happens after the task in TASK_INTERRUPTIBLE state receives a
signal and finshes with the associated handler. Does it go back to
sleep again ?
No, it stays in TASK_RUNNING.
Kind regards,
Iwo
.
- Follow-Ups:
- Re: linux sleep implementation
- From: Marco Gerber
- Re: linux sleep implementation
- References:
- linux sleep implementation
- From: Ask
- linux sleep implementation
- Prev by Date: linux sleep implementation
- Next by Date: Exportfs / kernel NFS server dentry question (2.6.9 kernel)
- Previous by thread: linux sleep implementation
- Next by thread: Re: linux sleep implementation
- Index(es):
Relevant Pages
|