接着 上一篇 “工作队列 的变化”
写了个例子,代码如下:
return 0;
}
/* Work submission. The first argument is the work function,
and the second argument is the argument to the work function */
int submit_work(void (*func)(struct work_struct *work), void * data)
{
mydrv_t* test;
test = (mydrv_t*)kmalloc(sizeof(mydrv_t), GFP_KERNEL);
memset(test, 0, sizeof(mydrv_t));
/* Init the work structure */
INIT_WORK(&(test->my_work), func);
test->data_for_work = data;
/* Enqueue Work */
queue_work(wq, &(test->my_work));
return 0;
}
static void mydrv_exit(void)
{
printk("cruel world, /n bye ,my dear!/n");
destroy_workqueue(wq);
}
module_init(mydrv_init);
module_exit(mydrv_exit);
//EXPORT_SYMBOL_GPL(queue_work);
MODULE_LICENSE("GPL");
编译执行后发现:
#ps -ef
...
root 5933 2 0 00:59 ? 00:00:00 [Josephdrv] <------<<<< 这里这个线程在模块移除后,仍然不退出,不知道什么原因
root 7572 2 0 01:50 ? 00:00:00 [g_queue]
...