Semaphores
摘要
Although simple synchronization problems can be solved by using lock algorithms, their implementations have quite a number of disadvantages. The oldest idea to eliminate some of these disadvantages is the synchronization construct of semaphores by Dijkstra. In this chapter, his ideas are presented, and many applications are used to demonstrate how semaphores can be used. This chapter specifies binary and—in the context of bounded buffers—general semaphores and discusses the interrelations between them, and after, Dijkstra’s sleeping barber is awakened, and the pitfalls of constructing general semaphores from binary ones are pointed out. The readers-writers problem and some of its solutions with semaphores lead to the pattern of the baton algorithm. It also deals with some specific issues: additive semaphores, barrier synchronization, the left-right problem, Dijkstra’s dining philosophers, the problem of the cigarette smokers, hints on the implementation of semaphores, and the convoy phenomenon.