Linux 内核线程的使用

来源:互联网 发布:罗马里奥进球数据 编辑:程序博客网 时间:2024/05/16 07:00


内核线程:

#include <linux/kthread.h>


struct task_struct  *pthread;


int thread_func(void *data) //线程要调用的函数
{
....
....
while(1){
....
....
msleep(200);
}

}


int __init xxx_init(void)
{
....
....
pthread = kthread_run(thread_a_func, "xxx", "driver name.");

if(IS_ERR(pthread)) {
ret = PTR_ERR(pthread);
pthread = NULL;
}
}


void __exit xxx_eixt(void)
{
if(pthread)
pthread = NULL;

}