I have a C++ application compiled with gcc that uses boost::shared_mutex
. I use them with shared_lock
(reader) and unique_lock
(writer).
I am running into writer starvation as explained in Does std::shared_mutex favor writers over readers?.
The linked article says that POSIX threads lib is used and links to another article how PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
can be used with pthreads. There is it described that I should initialize pthread_rwlock_init
and set pthread_rwlockattr_setkind_np
. However, my pthread rw locks are created by boost, and therefore I cannot pass such custom configuration to it.
Is there a way to globally prefer writers over readers such that boost will pick it up and what would such code look like?
Are there alternatives?