My understanding is: std::mutex
blocks other threads no matter if they want to read or write, whereas boost::shared_mutex
will allow multiple reads.
So my question is, should I always prefer a boost::shared_mutex
instead of a normal std::mutex
to allow the possibility of parallel reads to take place? Using a normal std::mutex
feels like I am denying some possible read throughput....?
I can't speak to the performance between the two of them, but my guess is that because of the extra logic boost::shared_mutex
might be slower. Asides from that, depending on how many readers you have you might block the writing thread longer than you would want as it would have to wait until all the read accesses are done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With