When a thread call pthread_cond_signal()
, Unix network programming said pthread_cond_signal()
just would nofity just one thread, beacause it isn't pthread_cond_broadcast()
. It means there is no race condition. However, the book does not say which thread would be notified, and how. Does the function wake thread randomly?
Straight from the man:
If more than one thread is blocked on a condition variable, the scheduling policy shall determine the order in which threads are unblocked.
The "scheduling policy" is the order the operating systems decided on. It's one of the four listed in the below link, but you don't really know (without some impressive hackery at least) which one is "first" anyway. It shouldn't matter either - all threads waiting on the condition should be equally ready to continue - otherwise you have a design problem.
Scheduling policies in Linux Kernel has a bit of discussion on some linux policies, and you can google from there if it's important.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With