Shared-Variable Programming: Semaphores
- Semaphores were the first and
remain one of the most important synchronization tools
- They can be used in two functions:
- to protect critical sections, or/and
- to implement signaling and scheduling
- Semaphores can be implemented using busy-waiting techniques, or using kernel, i.e. interrupts.
- Implemention using busy-waiting techniques has the disadvantage
that it wastes CPU time for spin-locking
- The concept and name of a semaphore
is motivated by one of the ways in which railroad traffic is synchronized
to avoid train collisions
- railroad semaphores can be viewed as mechanisms that signal
conditions in order to ensure mutually exclusive occupancy of critical
sections of track
- semaphores in concurrent programs are similar: they provide
a basic signaling mechanism and are used to implement mutual exclusion
and condition synchronization