mutex lock priority

后端 未结 5 1504
闹比i
闹比i 2021-01-14 02:58

In multithreading (2 thread) program, I have this code:

while(-1)
{
    m.lock();

    (...)

    m.unlock();
}

m is a mutex (

5条回答
  •  生来不讨喜
    2021-01-14 03:20

    The C++ standard doesn't make any guarantee about the order locks to a mutex a granted. Thus, it is entirely possible that the active thread keeps unlock()ing and lock()ing the std::mutex m without another thread trying to acquire the lock ever getting to it. I don't think the C++ standard provides a way to control thread priorities. I don't know what you are trying to do but possibly there is another approach which avoids the problem you encounter.

提交回复
热议问题