POSIX mutexes are clearly not the only mechanism you can use to synchronize access to a shared resource. This recipe will show you how to use another POSIX tool to achieve the same result. Semaphores are different from mutexes, and this recipe will teach you their basic usage, while the next will show you more advanced ones. A semaphore is a notification mechanism between threads and/or processes. As a rule of the thumb, try to use a mutex as a synchronization mechanism and semaphores as a notification mechanism. In this recipe, we'll develop a program that's similar to the one we built in the Using POSIX mutexes recipe, but this time, we'll protect the critical section with semaphores.




















































