Spurious wakeup
2014-02-19 14:46
113 查看
Spurious wakeup现象是在条件变量使用中出现的,即一个线程可能即使没有条件变量signal的时候也会被唤醒(a thread might be awoken from its waiting state even
though no thread signaled the condition variable.)这样会导致wait线程误以为条件成立,因此,正确做法是通过while判断相应的条件,如下所示:
参考资料:
http://en.wikipedia.org/wiki/Spurious_wakeup
https://gist.github.com/chenshuo/6430925
/article/1911641.html
http://stackoverflow.com/questions/4544234/calling-pthread-cond-signal-without-locking-mutex
though no thread signaled the condition variable.)这样会导致wait线程误以为条件成立,因此,正确做法是通过while判断相应的条件,如下所示:
/* In any waiting thread: */ while(!buf->full) wait(&buf->cond, &buf->lock); /* In any other thread: */ if(buf->n >= buf->size){ buf->full = 1; signal(&buf->cond); }
参考资料:
http://en.wikipedia.org/wiki/Spurious_wakeup
https://gist.github.com/chenshuo/6430925
/article/1911641.html
http://stackoverflow.com/questions/4544234/calling-pthread-cond-signal-without-locking-mutex
相关文章推荐
- ios-同步下载与异步下载
- 在WebView中调用js代码
- Xen bridge 超详细远离说明
- virtualbox on archlinux host
- 最牛B的Linux Shell命令(一)
- 【LeetCode】3Sum && 3Sum Closest && 4Sum
- UI篇--android实现底部按钮布局
- IOS 单例
- 解剖“秘书室”:三星共和国最顶级的中枢与大脑
- 东软睿道实训日记—第五天
- 从男女关系探讨用户的核心需求
- linux下调用openblas的segmentation fault错误
- g_main_loop
- imageView从网LOAD图片到SD卡并展示出来
- 8步打开android之门 NDK入门
- 手机游戏截图并通过JNI保存到手机内存特定文件夹下。
- ios开发,---学习项目
- shell中的 /dev/null
- super.getClass()方法调用返回结果的原因
- 很浅浅的谈谈 python doctest