I'm working on a program which suffer from starvation when one thread is doing more work than another. Critical section is protected by a reentrant QMutex, which is not fair.
In Java, you can specify a fairness parameter for a lock. Does C++,(or boost libraries) have any fair reentrant lock available? Preferably up to C++11.
I did some research before, there is shared_lock in boost, but I do not need a read/write lock. Just a lock which will guarantee that each thread has equal chances to enter the critical section.
Thank you very much.
C++ thread primitives are really based on Posix threads, and Posix does not have any fair mutexes. However, your question indicates that there is a problem with your design. There are two issues here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With