Game Development Reference
In-Depth Information
A bowl was placed at the beginning of the shared section of track. When an engineer
arrived, he would check the bowl. If it was empty, he would put a rock in it and drive
into the tunnel. He would then walk back, remove the rock, and continue on his trip.
This worked for a few days, and then the Peruvians noticed that their train never
arrived. Fearing the worst, a search team was sent out to find the train. It was waiting
at the junction, and as the search team watched, the Bolivian train roared by, not
even stopping. The Bolivian engineer ignored the rules, just put a rock in the bowl,
and never intended to take it out. He was fired and another, more honest, Bolivian
engineer replaced him.
For years nothing bad happened, but one day neither train arrived. A team was sent
to investigate, and they found that the trains had crashed, and two rocks were in the
bowl. Somehow both engineers must have passed each other in the dark tunnel while
placing their rocks. The two countries decided that the current system wasn ' t work-
ing, and something must be done to fix the problem. They decided that the bowls
were being used the wrong way. The Bolivian engineer would put a rock in the
bowl when he was driving across, and the Peruvian engineer would always wait
until the bowl was empty before driving across.
This didn
t even work for a single day. The Peruvian train had until this time run
twice per day, and the Bolivian train once per day. The new system prevented
crashes, but now each train could only run once per day since it relied on trading
permission to run through the pass. Again, the governments put their best minds at
work to solve the problem.
They bought another bowl.
Now, two bowls were used at the pass. Each engineer had his own bowl. When he
arrived, he would drop a rock into his bowl, walk to the other engineer
'
s bowl, and
check it. If there was a rock there, he would go back to his bowl, remove the rock,
and take a siesta. This seemed to work for many years, until both trains were so late a
search team was sent out to find out what happened.
Luckily, both trains were there, and both engineers were simultaneously dropping
rocks into their bowls, checking the other, finding a rock, and then taking a siesta.
Finally, the two governments decided that bowls and rocks were not going to solve
this problem.
What they needed was a semaphore.
'
Test and Set, the Semaphore, and the Mutex
The computer software version of a semaphore relies on a low-level hardware
instruction called a test-and-set instruction. It checks the value of a bit, and if it is
 
 
Search WWH ::




Custom Search