Quoting from the POSIX specification:
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.
So the choice can be random, it can be a queue, it can be whatever the scheduler wishes to do.
CLICK HERE to find out more related problems solutions.