kthread_create创建线程
kthread_stop发送停止线程信号
kthread_should_stop接收停止线程信号
create:
static int printsth(void* data){int cnt = 150000;while(cnt > 0 &&! kthread_should_stop()){printk("kct: %d\n", cnt);cnt--;msleep(1000);}return 0;
}
stop:
static void __exit kct_exit(void){kthread_stop(thd_printsth);printk("kct_exit\n");
}
卸载模块时把线程停掉。也可以在别的地方停掉它。
疑惑:
1.如何判断线程是否已经正常退出,来判断是否使用kthread_stop来结束它。
2.task_struct->sched_entry->on_rq和task_struct->state是否会因为线程内调用msleep导致状态变化。