RLT*_*RLT 2 c++ macos boost mutex boost-interprocess
我有一些代码等待共享内存上的写操作.如果没有人写,它继续等待.
Test* Foo::Get()
{
boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> lock ( mutex ) ; // mutex is boost::interprocess::interprocess_mutex
if ( this->check == 0 )
this->interprocessCondition.wait ( lock ) ; // interprocessCondition is boost::interprocess::interprocess_condition
...
}
Run Code Online (Sandbox Code Playgroud)
当我抽样时,我发现它消耗了大约90%的CPU.
有人可以帮我解决这个性能问题吗?请参阅附图.

boost::interprocess不幸的是,在很多平台上使用忙等待锁(显然包括OSX).您将需要使用实际睡眠的平台本机锁.