boost::mutex和boost::timed_mutex的性能差异
performance difference of boost::mutex and boost::timed_mutex
我需要通过互斥来保护资源。为了改进诊断,我正在考虑使用timed_mutex
(未测试的代码)进行死锁警告:
boost::timed_mutex m;
// first thread accessing the resource very frequently
while(...){
boost::mutex::scoped_lock(m);
// ...
}
// ...
// another thread accessing the resource, only occasionally
while(m.timed_lock(boost::get_system_time()+boost::posix_time::seconds(10)){
cerr<<"Waiting for lock for (additional) 10 seconds; deadlocked?"<<endl;
}
当与两个循环中的简单mutex
的两个无条件锁相比时,我会看到timed_mutex
的性能差异吗?(平台是POSIX,以防产生影响)
答案在于pthread库的实现。我不认为有太大的区别,但你能做的最好的事情就是测量它。
相关文章:
- BOOST :: MUTEX版本与调试构建
- 使用Boost ::与包含Boost :: Mutex的类绑定
- boost::interprocess_mutex与进程本地boost::mutex
- Boost Mutex implementation for Windows
- 为什么我必须有一个 boost::mutex for boost::condition_variable
- boost::mutex和boost::timed_mutex的性能差异
- 如何使用boost::mutex作为std::map中的映射类型
- boost::mutex::timed_lock not on Linux
- 与 boost::interprocess_mutex 相比,为什么不在共享内存中使用 boost::mutex
- boost::mutex 无法帮助避免C++程序中的竞争条件
- 为什么 boost::mutex 比 std::mutex 快 vs2013.
- boost::mutex 在 Visual Studio 中支持 try_lock_for,但在 Xcode 中不支持
- boost::mutex 和 boost::timed_mutex 之间的区别
- Boost,指向互斥对象的指针,能起作用吗?boost::mutex和std::vector,不可复制的问题
- 在boost::mutex构造函数中同时写入同一内存区域可能存在错误
- 使用boost::mutex作为类的私有成员
- 可变boost::mutex可以分离锁和等待函数
- Boost::mutex, pthread_mutex_destroy失败的调试建议
- Boost::mutex - 是否可以将其锁定在一个类函数中并在另一个类函数上解锁
- replacing boost:: mutex