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