Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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....?

like image 257
user997112 Avatar asked Aug 11 '14 10:08

user997112


1 Answers

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.

like image 134
Harald Scheirich Avatar answered Sep 26 '22 02:09

Harald Scheirich