vendredi 1 juillet 2016

How can I avoid lock of many threads on mutex which locked (owned) by thread which sleep?

As known if thread-1 locks the std::mutex and occurs switch of thread-1, and if at this time many threads (2, 3, 4 ...) want to lock this mutex, then all these threads will locked and will be waiting for switch-on thread-1.

The solution to this is to use lock-free algorithms. But if requre to use a mutex, that is some solution to avoid such a situation?

  1. How can I find out in advance for 100 cycles before the imminent switching of thread?

  2. Or how can I raise an exception in advance for 100 cycles before switching the flow on Linux x86_64?

  3. Or how can I to make continue work of thread for some time (100 cycles)?

Aucun commentaire:

Enregistrer un commentaire