高手请看:关于工作队列workqueue使用方法代码是不是有问题,多谢
时间:2010-05-25
来源:互联网
下面是网上摘抄的一段代码,我看了一下似乎有点问题,见下:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/workqueue.h>
static struct workqueue_struct *queue = NULL;
static struct work_struct work;
static void work_handler(struct work_struct *data)
{
printk(KERN_ALERT "work handler function.\n");
}
static int __init test_init(void)
{
queue = create_singlethread_workqueue("helloworld"); /*创建一个单线程的工作队列*/
if (!queue)
goto err;
INIT_WORK(&work, work_handler);
schedule_work(&work);
return 0;
err:
return -1;
}
static void __exit test_exit(void)
{
destroy_workqueue(queue);
}
上面的test_init部分是不是没有实现作者的意图?因为 schedule_work(&work);是使用默认的系统events工作队列,而作者原意是想使用自己创建的queue,应该是调用函数queue_work(queue,&work),,是不是这样啊,呜呜~~~~高手们解释一下吧,多谢!
#include <linux/module.h>
#include <linux/init.h>
#include <linux/workqueue.h>
static struct workqueue_struct *queue = NULL;
static struct work_struct work;
static void work_handler(struct work_struct *data)
{
printk(KERN_ALERT "work handler function.\n");
}
static int __init test_init(void)
{
queue = create_singlethread_workqueue("helloworld"); /*创建一个单线程的工作队列*/
if (!queue)
goto err;
INIT_WORK(&work, work_handler);
schedule_work(&work);
return 0;
err:
return -1;
}
static void __exit test_exit(void)
{
destroy_workqueue(queue);
}
上面的test_init部分是不是没有实现作者的意图?因为 schedule_work(&work);是使用默认的系统events工作队列,而作者原意是想使用自己创建的queue,应该是调用函数queue_work(queue,&work),,是不是这样啊,呜呜~~~~高手们解释一下吧,多谢!
作者: honest581 发布时间: 2010-05-25
(1)结论是正确的。
(2)缺省队列的特点也正在于此,不需要(新建)queue结构.代码
中虽然创建了,也没有使用。
(2)缺省队列的特点也正在于此,不需要(新建)queue结构.代码
中虽然创建了,也没有使用。
作者: linux_sir_huang 发布时间: 2010-05-27
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28