What is the `pthread_mutex_lock()` wake order with multiple threads waiting?

后端 未结 3 1524
北海茫月
北海茫月 2020-12-19 01:35

Suppose I have multiple threads blocking on a call to pthread_mutex_lock(). When the mutex becomes available, does the first thread that called pthread_mu

3条回答
  •  清酒与你
    2020-12-19 02:01

    "If there are threads blocked on the mutex object referenced by mutex when pthread_mutex_unlock() is called, resulting in the mutex becoming available, the scheduling policy shall determine which thread shall acquire the mutex."

    Aside from that, the answer to your question isn't specified by the POSIX standard. It may be random, or it may be in FIFO or LIFO or any other order, according to the choices made by the implementation.

提交回复
热议问题