文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>sleep_on

sleep_on

时间:2007-02-14  来源:ffjnfj

一般的使用情况: >
    while (we_have_to_wait)
    /* race condition */
    sleep_on(&some_wait_queue);
The problem is that the situation can change between the test (in the while
loop) and when the process actually goes to sleep. If the wakeup event happens
between the two, the process will miss it and may sleep forevermore.
sleep_on的主要问题就是在加入wait queue之后没机会再判断条件是否已经满足了

最好是使用wait_event族的函数: >
    DEFINE_WAIT(_ _wait);
    for (;;) {
    /* (1) */
        prepare_to_wait(&wq, &_ _wait, TASK_UNINTERRUPTIBLE);
    /* (2) */
        if (condition)
    /* (3) */
            break;
        schedule( );
    }
    finish_wait(&wq, &_ _wait);
这类函数就没有sleep_on的问题。因为在放入wait queue(prepare_to_wait)之后再次
检查了condition:
1) 此时别的任务调用wakeup,而且满足条件了,那么只是挂入wait queue而已,经if之后,就马上出来了。
2) 会马上从if break
3) wakeup会把把该task重新加入到runqueue
schedule会把status不是TASK_RUNNING的task去激活,也就是不会被调度到,也就是说只有在schedule之后才可能被deactive
wakeup会把task激活并置状态为TASK_RUNNING,这样schedule就不会干上面提到的事

 vim:ft=help

排行榜 更多 +
我的酒厂

我的酒厂

音乐节奏 下载
一起单车

一起单车

模拟经营 下载
文字成精

文字成精

休闲益智 下载