Boost :: shared_mutex multitext with multiple readers / single writers

I am trying to use boost :: shared_mutex to implement a mutex with multiple readers / single writers. My question is pretty simple, is it possible for a thread to get reader access to shared_mutex when another thread tries to lock this shared_mutex for writing? For example, I have 10 threads, only one of them can write,

  • In stream 1 there is shared_lock for this shared_mutex and is trying to read something
  • In stream 2 there is shared_lock for this shared_mutex and is trying to read something
  • thread 3 has a unique_lock on this shared_mutex and is trying to write something
  • thread 4 has shared_lock for this shared_mutex and is trying to read something
  • In thread 5 there is shared_lock for this shared_mutex and is trying to read something

Currently shared_mutex is shared by thread 2 lock, my question is, is it possible for thread 4 to have read access to this shared_mutex, before thread 3 can write? Is it possible for reader / writer mutexes to ever get into a fasting situation, for example, 100 readers are against. 1 writer?

Thanks.

+3
source share
1 answer

boost::shared_mutex leave a fairness policy before implementation. This may be true, reader-writer or writer-reader, therefore, depending on which version of your version may turn out to be hungry, it may be written.

+3
source

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


All Articles