Keep in mind that acquiring a lock for a read / write mutex is more expensive than acquiring a regular std::mutex . As a result, a read / write mutex will not improve performance if you have frequent but short read operations. It is better suited for scripting, as read operations are frequent and expensive. To quote a post by Anthony Williams :
The cost of locking shared_mutex is higher than the cost of locking plain std :: mutex, even for reader threads. This is a necessary part of the functionality --- there are more possible shared_mutex states than a mutex, and the code should handle them correctly. This cost is included both in the size of the object (which the implementation and my POSIX implementation includes as a simple mutex and condition variable), as well as when locking and unlocking an operation.
In addition, shared_mutex is a point of contention, and therefore scalable. Locking shared_mutex necessarily changes the state of the mutex, even to block reading. Therefore, the cache line containing the shared_mutex state must be transmitted depending on which processor is executing the lock or unlock operation.
If you have many threads that perform frequent short read operations, then in a multiprocessor system this can lead to a large amount of ping-pong cache, which will significantly affect system performance. In this case, you can also adopt a simpler design simply by using a simple mutex, as readers are essentially serialized anyway.
If reading is not frequent, then there is no claim, so you don’t have to worry about compatible readers, and a simple mutex for this scenario is enough anyway.
If the read operations take a lot of time, then the consequence of this statement is less noticeable, since it is overshadowed by the time spent while holding the read lock. However, the execution of labor-intensive operations while fixation is the smell of design.
In the vast majority of cases, I think there are better alternatives to shared_mutex. It could be a simple mutex, atomic support for shared_ptr, the use of a carefully designed parallel container, or something else, depending on the context.