linux sleep implementation



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 ?

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 ?

Thanks

.



Relevant Pages

  • Re: Sleeping thread not receive signal until it wakes up
    ... Later versions of the kernel lock the kernel when an ioctl() is ... This means that if you sleep in the ioctl, ... if// Before sleeping section ...
    (Linux-Kernel)
  • Re: Kconfig variable "COBALT" is not defined anywhere
    ... Robert P. J. Day wrote: ... > There were other patches which added more COBALT support, ... > doing proper Cobalt support for modern kernels. ... Training and Annoying Kernel Pedantry ...
    (Linux-Kernel)
  • Re: ath_rate_sample build error?
    ... "Robert C. Noland III" wrote: ... I just recompiled my kernel. ... > wireless NICs. ...
    (freebsd-current)
  • Re: Problems with Rivatv installation
    ... driver module to be inserted into the kernel) would be part ... Red Hat installations have not been making the link.) ... Robert Riches ...
    (linux.redhat)
  • Re: O2micro smartcard reader driver.
    ... soon as possible in the upstream kernel before some kernel api changes ... IIRC there were some suspicious sleep saying it was sleeping a microsecond and sleeping one millisecond! ... I'm also a bit concerned about the userspace "driver" for pscd which comes with the original driver once the patch will be part of the default kernel. ...
    (Linux-Kernel)