CV broadcast wakeup

As we saw previously, the pthread_cond_signal(3P) API is used to unblock a thread that is blocked upon a particular CV. A variant of this API is as follows:

int pthread_cond_broadcast(pthread_cond_t *cond);

This API allows you to unblock multiple threads that are blocking on the same CV. So, for example, what if we have three threads blocking on the same CV; when the application calls the pthread_cond_broadcast(3P), which thread will run first? Well, this is like asking, when threads are created, which one will run first (recall these discussions from the previous chapter). The answer, of course, is that, in the absence of particular scheduling policies, it is indeterminate. The same answer holds for the question when ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.