Named condition variables
As we explained before, similar to named POSIX mutexes, we need to allocate a POSIX condition variable from a shared memory region in order to use it in a multi-processing system. The following example, example 18.4, shows how to do so in order to make a number of processes count in a specific order. As you know from Chapter 16, Thread Synchronization, every condition variable should be used together with a companion mutex object which protects it. Therefore, we will have three shared memory regions in example 18.4; one for the shared counter, one for the shared named condition variable, and one for the shared named mutex protecting the shared condition variable.
Note that instead of having three different shared memories, we could also use a single shared memory. This is possible by defining a structure that encompasses all the required objects. In this example, we are not going to take this approach and we will define a separate shared memory region for...