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.
United States
Great Britain
India
Germany
France
Canada
Russia
Spain
Brazil
Australia
Singapore
Hungary
Ukraine
Luxembourg
Estonia
Lithuania
South Korea
Turkey
Switzerland
Colombia
Taiwan
Chile
Norway
Ecuador
Indonesia
New Zealand
Cyprus
Denmark
Finland
Poland
Malta
Czechia
Austria
Sweden
Italy
Egypt
Belgium
Portugal
Slovenia
Ireland
Romania
Greece
Argentina
Netherlands
Bulgaria
Latvia
South Africa
Malaysia
Japan
Slovakia
Philippines
Mexico
Thailand