How to kill a wait queue in kernel module?

白昼怎懂夜的黑 提交于 2019-12-06 16:34:44

Common way for wait within kernel thread:

void thread1(void)
{
    while(!kthread_should_stop())
    {
        ...
        wait_event_interruptible(wait_queue,
             does_buffer_have_data() || kthread_should_stop());
        if(kthread_should_stop()) break;
        ...
    }
}

void module_cleanup(void)
{
    kthread_stop(t);
}

Function kthread_should_stop checks stop flag for current thread.

Function kthread_stop(t) sets stop flag for thread t, 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 after kthread_stop but only rechecks condition.

So, if waiting for event wants to be returned after kthread_stop, it should check stop flag explicitely in condition.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!