I am studying the locking mechanisms in an OS and came across these POSIX functions:
pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m);
pthread_cond_signal(pthread_cond_t *c);
I fully understand the idea behind the sleep/wake up here. But I am not sure how is this done in HW and how is it affecting scheduling...etc
My understanding that when a thread executes: pthread_cond_wait() it goes to sleep (blocks), but what does this actually mean? Yes it gets de-scheduled and moved into a blocked state somewhere in a privileged queue, But when another process executes pthread_cond_signal(), how does the CPU wakes up the blocked thread? Is it during the timer interrupt that the kernel goes and checks all condition variables and then decides to wake up a thread associated with one that got freed up?
I couldn't find a detailed explanation on this anywhere online, or maybe I am not looking correctly.
Any help is highly appreciated.
signal
, there is a user-space list of threads waiting on the conditional variable, and one of those gets woken with afutex
system call. Checking an array of condition variables every tick would be very slow ...