作者enduser (淡水..)
看板LinuxDev
标题Re: [问题] 关於 schedule_timeout 的用法
时间Fri Mar 5 14:50:56 2010
※ 引述《Spig (Spig)》之铭言:
: ※ 引述《enduser (淡水..)》之铭言:
: : 请教一下大家,我想在五秒之後 printk 一段讯息,
: : 但是听说用 busy wait 方式不好,所以可以用 schedule_timeout
: 不是不好.... 是不能用 busy waiting....
: 如果你想要五秒後才去跑一些东西, 建议二个选择..
: 1. 设 Timer
: 2. 使用 kthread
可是我之前写的版本是像这样:
unsigned long timeout = jiffies + (5*HZ);
while (1)
{
if (time_after(jiffies, timeout))
{
printk(KERN_ALERT "Hello, world after 5 secs\n");
break;
}
}
不知道这样算不算 busy wait?
後来上一篇改成这样有一样的效果
schedule_timeout_interruptible (5*HZ);
printk(KERN_ALERT "Hello, world after 5 secs\n");
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.168.201.228
※ 编辑: enduser 来自: 118.168.201.228 (03/05 14:51)
1F:→ franklin:题外话..time_after是用来比较时间用.. 03/06 22:28
2F:→ franklin:time_after(a,b) returns true if the time a is after b 03/06 22:38