C++ boost::mutex和boost::timed_mutex的性能差异

C++ boost::mutex和boost::timed_mutex的性能差异,c++,performance,boost,locking,mutex,C++,Performance,Boost,Locking,Mutex,我需要通过互斥来保护资源。为了改进诊断,我正在考虑使用timed_mutex(未测试代码)发出死锁警告: boost::timed_mutex m; //第一个线程非常频繁地访问资源 而(…){ boost::mutex::作用域锁定(m); // ... } // ... //另一个线程只是偶尔访问资源 while(m.timed_lock(boost::get_system_time()+boost::posix_time::seconds(10)){ cerr答案在于pthread库的实现

我需要通过互斥来保护资源。为了改进诊断,我正在考虑使用
timed_mutex
(未测试代码)发出死锁警告:

boost::timed_mutex m;
//第一个线程非常频繁地访问资源
而(…){
boost::mutex::作用域锁定(m);
// ...
}
// ...
//另一个线程只是偶尔访问资源
while(m.timed_lock(boost::get_system_time()+boost::posix_time::seconds(10)){

cerr答案在于pthread库的实现。我不认为有太大的区别,但最好是对它进行度量

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;
}