我需要通过互斥来保护资源。为了改善诊断,我正在考虑使用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,以防有什么不同)
发布于 2012-12-12 05:44:29
答案取决于pthread库的实现。我不认为有很大的区别,但你能做的最好的就是测量它。
https://stackoverflow.com/questions/11815557
复制相似问题