What is the `pthread_mutex_lock()` wake order with multiple threads waiting?
c, multithreading, pthreads
Solution
When the mutex becomes available, does the first thread that called `pthread_mutex_lock()` get the lock?
No. One of the waiting threads gets a lock, but which one gets it is not determined.
FIFO order?
FIFO mutex is rather a pattern already. See Implementing a FIFO mutex in pthreads
Problem
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_mutex_lock()` get the lock? That is, are calls to `pthread_mutex_lock()` in FIFO order? If not, what, if any, order are they in? Thanks!