Why use std :: mutex instead of boost :: shared_mutex?

I understand: std::mutex blocks other threads regardless of whether they want to read or write, while boost::shared_mutex allows several reads.

So my question is: should I always prefer boost::shared_mutex over the usual std::mutex to allow parallel readability? Using regular std::mutex seems like I'm denying some possible read throughput ...?

+5
source share
1 answer

I can not talk about performance between the two of them, but I assume that due to the additional logic boost::shared_mutex can be slower. Because of this, depending on how many readers you have, you can block the flow of letters longer than you would like, since he would have to wait until all the reads were completed.

+7
source

Source: https://habr.com/ru/post/1200017/


All Articles