mutex lock priority

后端 未结 5 1590
闹比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:38

    There are no guarantees provided by C++ or underlying OS.

    However, there is some reasonable degree of fairness determined by the thread arrival time to the critical region (mutex in this case). This fairness can be expressed as statistical probability, but not a strict guarantee. Most likely this choice will be down to OS execution scheduler, which will also consider many other factors.

提交回复
热议问题