免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1364 | 回复: 1
打印 上一主题 下一主题

内核线程问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-28 19:51 |只看该作者 |倒序浏览
我想起个内核线程定时的去做事情
但是为什么init模块就是死机啊
日志里面没有任何信息
  1. struct timer_list mytimer;
  2. static void myfunc(unsigned long data)
  3. {
  4.         printk("%s/n", (char *)data);
  5.         dequeue();
  6.         mod_timer(&mytimer, jiffies + 2*HZ);
  7. }
  8. static int __init mytimer_init(void)
  9. {
  10.         setup_timer(&mytimer, myfunc, (unsigned long)"Hello, world!");
  11.         mytimer.expires = jiffies + HZ;
  12.         add_timer(&mytimer);
  13.         return 0;
  14. }
  15. static void __exit mytimer_exit(void)
  16. {
  17.         del_timer(&mytimer);
  18. }
  19. static struct task_struct *_task;
  20. int thread_func(void *argm)
  21. {
  22.         printk("thread_func\n");
  23.         mytimer_init();
  24.         //     // wait to exit
  25.         while(!kthread_should_stop())
  26.         {
  27.         //        printk("wait()\n");
  28.              mdelay(1000);
  29.         }
  30.         return 0;
  31. }
  32. void exit_code(void)
  33. {
  34.         kthread_stop(_task);   //发信号给task,通知其可以退出了
  35. }
  36. static int __init this_init(void)
  37. {
  38.        _task = kthread_run(thread_func, NULL, "thread_func2");
  39.         if (!IS_ERR(_task))
  40.         {
  41.                 printk("kthread_create done\n");
  42.         }
  43.         else
  44.         {
  45.                 printk("kthread_create error\n");
  46.         }

  47.         return ret;

  48. }
复制代码

论坛徽章:
0
2 [报告]
发表于 2012-02-29 09:16 |只看该作者
请问代码有什么问题么,原来没用过内核线程啊,默认的情况下kthread是可以被中断的?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP