O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Semaphores

GCD provides semaphores – objects that threads can wait on and signal with (where signal is not a Unix signal). There are two kinds of semaphores: binary semaphores and counting semaphores.

A binary semaphore is a single flag. The flag starts out signaled. Waiting on it claims the flag. Any further attempts to wait on it require blocking until it is signaled again.

A counting semaphore is often initialized with the count of some resource and then used to allocate that resource. Waiting on the semaphore claims a unit, and signaling releases that claim. Only when the units have run out (the semaphore’s count being zero) does waiting on the semaphore actually block, requiring waiting for a unit to become available. Waiting can block, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required