LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1335|回复: 1

高手请看:关于工作队列workqueue使用方法代码是不是有问题,多谢

[复制链接]
发表于 2010-5-25 15:43:19 | 显示全部楼层 |阅读模式
下面是网上摘抄的一段代码,我看了一下似乎有点问题,见下:
#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),,是不是这样啊,呜呜~~~~高手们解释一下吧,多谢!
发表于 2010-5-27 18:12:41 | 显示全部楼层

缺省队列

(1)结论是正确的。
(2)缺省队列的特点也正在于此,不需要(新建)queue结构.代码
   中虽然创建了,也没有使用。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表