pthread_cond_wait与signal
来源:互联网 发布:php radio行取值 编辑:程序博客网 时间:2024/05/17 07:53
http://www.domaigne.com/blog/computing/condvars-signal-with-mutex-locked-or-not/
pthread_mutex_lock(&mutex);predicate=true;pthread_cond_signal(&cv); // OR: pthread_mutex_unlock(&mutex);pthread_mutex_unlock(&mutex); // : pthread_cond_signal(&cv);
Signal with Mutex Locked
On some platforms, the OS performs a context switch to the woken thread right after the signal/broadcast operation, to minimize latency. On a single processor system, this may lead to unnecessary context switches if we signal or broadcast while holding the mutex.
Indeed, consider the scenario shown in figure 1. The thread T2 is blocked on the condition variable. T1 signals the condition while holding the associated mutex. A context switch to T2 occurs and T2 wakes up. But before returning frompthread_cond_wait
, T2 needs to lock the mutex. However that mutex is already hold by T1. As a result T2 blocks (but this time contends for the mutex) and a context switch to T1 occurs. Then T1 unlocks the mutex, and T2 becomes finally runnable. The situation appears to be even worse, if we broadcast the condition variable to several threads.
- pthread_cond_wait与signal
- 线程间通讯《代码》pthread_cond_wait/signal
- pthread_cond_wait()与pthread_cond_signal()
- pthread_cond_wait与mutex、while
- 详解pthread_cond_wait与pthread_cond_signal
- pthread_cond_wait与pthread_cond_signal
- pthread_cond_signal与pthread_cond_wait详解
- pthread_cond_signal与pthread_cond_wait详解
- pthread_cond_wait()与pthread_cond_signal()
- pthread_cond_wait()与pthread_cond_signal()
- pthread_cond_signal与pthread_cond_wait详解
- pthread_cond_signal与pthread_cond_wait详解
- pthread_cond_signal与pthread_cond_wait
- pthread_cond_wait()与pthread_cond_signal()
- pthread_cond_signal与pthread_cond_wait详解
- 关于 pthread_cond_wait 和 pthread_cond_signal , signal 无效的问题
- pthread_cond_wait()
- pthread_cond_wait
- QT学习2:Table/List/Tree的View,Widget,Model相关
- lex和yacc简介
- 【翻译自mos文章】asm 归档路径满了
- 命令行查看WIN系统的激活信息
- 线程局部变量与 __thread
- pthread_cond_wait与signal
- 为什么手机从3寸发展到5寸?
- 【翻译自mos文章】回收 asm磁盘空间的方法
- eclipse之tomcat (server options)
- Lazarus开发串口通信
- 云计算-互联网-云计算服务的传播
- 详解自定义JSP标签
- 读《百度基础架构技术发展之路》有感
- cheap louis vuitton handbags-882603