I am trying to use boost::shared_mutex to implement a multiple-reader / single-writer mutex. My question is fairly simple, is it possible for a thread to gain reader access to a shared_mutex, when another thread tries to lock that shared_mutex for writing? For example, I have 10 threads, only one of them can write,
The shared_mutex is currently shared locked by thread 2, my question is whether it is possible that thread 4 can gain read access to that shared_mutex, before thread 3 can write? Is it possible for a reader/writer mutex ever gets into a starvation situation, e.g., 100 reader v.s. 1 writer?
Thanks.
Apparently the boost::shared_mutex
leaves the fairness policy up to the implementation. It can be either fair, reader-over-writer or writer-over-reader so depending on which it is for your particular version it's possible that the writer can be starved.