是否有C++ 11等效的boost::shared_mutex.或者在C++ 11中处理多个读者/单个写入者情况的另一个解决方案?
我有一个8个线程之间的共享哈希表(我是一个8核PC),每个线程在哈希表中读写.
在示例1中,我使用了经典的互斥锁,并且在示例2中所有8个核心都是100%我使用了shared_timed_mutex,因为读取访问可以在竞争中但是所有8个核心都在40%
问题出在哪儿?
example 1:
mutex mutex_hash;
-- thread --
mutex_hash.lock();
//read
mutex_hash.unlock();
..
mutex_hash.lock();
//write
mutex_hash.unlock();
Run Code Online (Sandbox Code Playgroud)
============================
example 2:
shared_timed_mutex mutex_hash;
-- thread --
mutex_hash.lock_shared();
//read
mutex_hash.unlock_shared();
..
mutex_hash.lock();
//write
mutex_hash.unlock();
Run Code Online (Sandbox Code Playgroud)