In the computer world, a semaphore controls access to a resource or resources that need to be shared by multiple processes. This is particularly important in the kernel where interrupt routines have to be careful about kernel structures other processes may be modifying, and when multiple CPU's are used (SMP).
A semaphore can be binary or otherwise (binary means that if it is in use, nothing else should use it); non binary versions are used where there is more than one of whatever it is we are sharing, but there is some limit.
The general rule for acquiring a semaphore is that if its value is 0, the process sleeps until it isn't. If it is not, the semaphore is decremented and the process has access to whatever the semaphore is protecting.
Whether binary or not, the important implementation detail is that testing and decrementing has to be "atomic"; that is, no other process can sneak in while those actions are taking place.
Ordinary user programs sometimes have need of such things too.
Got something to add? Send me email.
More Articles by Tony Lawrence © 2011-03-27 Tony Lawrence
Today’s computers are not even close to a 4-year-old human in their ability to see, talk, move, or use common sense. One reason, of course, is sheer computing power. It has been estimated that the information processing capacity of even the most powerful supercomputer is equal to the nervous system of a snail—a tiny fraction of the power available to the supercomputer inside [our] skull. (Steven Pinker)