作者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)
→ franklin:題外話..time_after是用來比較時間用.. 03/06 22:28
→ franklin:time_after(a,b) returns true if the time a is after b 03/06 22:38