I am new to kernel module. Using a wait queue, I am blocking the thread until the buffer has data. Using hrtimer
, I am periodically waking up the queue. Now, the problem is even after I remove the kernel module, I could see that the process "thread1"
is still running. I think the issue is that the wait queue is waiting forever and the process got blocked here. Please help me how can I kill the wait queue when I remove my module.
void thread1(void)
{
while (thread_running) {
...
wait_event_interruptible(wait_queue, does_buffer_have_data());
...
}
}
Common way for wait within kernel thread:
Function
kthread_should_stop
checksstop
flag for current thread.Function
kthread_stop(t)
setsstop
flag for threadt
, interrupt any waiting performed by this thread, and waits while the thread is finished.Note, that while
kthread_stop
interrupts waiting, it doesn't set any pending signal for the thread.Because of that interruptible wait for event (
wait_event_interruptible
and so) doesn't return-EINTR
just afterkthread_stop
but only rechecks condition.So, if waiting for event wants to be returned after
kthread_stop
, it should checkstop
flag explicitely in condition.