Three classical IPC problems

1. The Dining Philosophers Problem

The key point is to make sure that a philosopher should get two forks at one time, not separately. That means, one philosopher should check to see if he can get into the state of eating first, then get two forks or just wait. If he checks to see if he can get the left fork first, get it, then the right one, a deadlock may occur, even the chance is very small.

This problem is useful for modeling processes that are competing for exclusive access to a limited number of resources, such as I/O devices.

 

2. The Readers and Writers Problem

In this problem, one thing that should be concerned most is how to make writer, who has the exclusive access, not be blocked by the readers who come along after his arrival.

This problem models access to a data base.

 

3. The Sleeping Barber Problem

The solution uses three semaphores, one counts waiting customers (excluding the customer in the barber chair, who is not waiting), one presents the number of barbers who are idle waiting for customers, and one used for mutual exclusion. Besides, a variable is needed, which also counts the waiting customers. It is essentially a copy of the first semaphore. The reason for having such a variable is that there is no way to read the current value of a semaphore. In this solution, a customer has to count the number of waiting customers.

Like problem No.2, although they do not involve data transfer, they still belong to the area of IPC because they involve synchronization between multiple processes.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章