POSIX concurrency control
In this section, we are going to have a look at possible control mechanisms that are offered by the pthread library. Semaphores, mutexes, and condition variables alongside different types of locks are used in various combinations to bring determinism to multithreaded programs. First, we start with POSIX mutexes.
POSIX mutexes
The mutexes introduced in the pthread library can be used to synchronize both processes and threads. In this section, we are going to use them in a multithreaded CÂ program in order to synchronize a number of threads.
As a reminder, a mutex is a semaphore that only allows one thread at a time to enter the critical section. Generally, a semaphore has the potential to let more than one thread enter its critical section.
Note:
Mutexes are also called binary semaphores because they are semaphores that accept only two states.
We start this section by resolving the data race issue observed as part...