NVIDIA Interview Question
Software Engineer / Developerswhy do we need sleep in the kernel?
Kernel is like a machine which run everything , if kernel sleep , other thread won't get a chance to run , so the whole system will stop , unless you want to process interrupt.
I guess if in kernel you want this thread to sleep, you can do a context switch to let the current thread sleep, then you can let other thread run.
if you really want to sleep in kernel, you can disable interrupt, so that the scheduler won't have a chance to work , you will be able to sleep as long as you want with a while loop.
By making a call to function :
- Varun Anand June 05, 2013thread_switch(S_SLEEP /*State*/, wchan *wc /*wait channel*/)
This would put curthread inside the kernel to sleep by putting it on sleep queue and changing its state from runnable to sleep.