void main()
{
.....
pthread_mutex_init(&lock)
pthread_create(fun,...)
pthread_create(fun,...)
pthread_create(fun,...)
}
void fun()
{
pthread_mutex_lock(&lock)
...........
pthread_mutex_unlock(&lock)
}
In the code above, I created 3 threads calling same function fun. I can tell you that execution of fun takes long than creating the threads. So there are 3 threads initially. But 1st thread is already executing after taking lock. Now 2nd and third thread are waiting. My question is once the lock is released which thread will be scheduled. Is it 2nd thread and then third or depends on the scheduler. Does scheduler maintain any kind of queue for the waiting threads and schedules it in FIFO manner?