Fair Reentrant Lock C ++

I am working on a program that suffers from hunger when one thread does more work than another. The critical section is protected by reentrant QMutex, which is not fair.

In Java, you can specify an equity option to block. Does C ++ (or acceleration libraries) have an accessible reentrant lock available? Preferably up to C ++ 11.

I used to do some research, boost has share_lock, but I don't need a read / write lock. Just a lock that ensures that every thread has an equal chance of entering a critical section.

Thank you very much.

+5
source share
1 answer

C ++ primitive drives are actually based on Posix threads, and Posix does not have any good mutexes. However, your question indicates that there is a problem with your design. There are two questions here:

  • Repeater mutexes are a sign of a problem. You must be 100% in control of the ownership and life cycle of the mutex. If you need a reentry mutex, then the design is messy.
  • The topic voice in your description is the result of improperly designed message flows. If a thread needs a mutex that is held for a while, this means that you are effectively developing a single-threaded system and do not need any threads.
+2
source

All Articles