Operating Systems Week 7 5 th Semester, 2012 IN. 5012 Fei Peng PAI Group University of Fribourg
6.1 Dining Philosophers Problem a. In the solution to the dining philosophers problem (Fig. 2-20), why is the state variable set to HUNGRY in the procedure take_forks? A philosopher may move into the eating state only if neither of his neighbours is eating. Philosopher i's neighbours are defined by the macros LEFT and RIGHT. The program uses an array of semaphores, one per philosopher, so hungry philosophers can block if the needed forks are busy. If a philosopher blocks, neighbours can later see that he is hungry by checking his state in test, so he can be awakened when the forks are available.
6.1 Dining Philosophers Problem b. Consider the put_forks in [Tan 06, Fig.2-20]. Suppose that the variable state[i] was set to THINKING after the two calls to test. How would this change affect the solution for the case of 3 philosophers? For 100 philosophers? For 3 philosophers: The change would mean that after a philosopher stopped eating, neither of his neighbours could be chosen next. With only two other philosophers, both of them neighbours, the system would deadlock. For 100 philosophers: In case of 100 philosopher it won t deadlock. But we lost some parallelism because some philosophers have to wait for a moment.
6.3 The Sleeping Barber Problem Problem description Barber: he checks if there are customers waiting If true The barber cuts his hair, and checks if another customer is waiting. Else The barber sleeps until a customer wakes him up. Customers: the customers enter the shop and check if the barber is sleeping If true He wakes up the barber. Else He waits. // because there are other customers in front of him.
6.3 The Sleeping Barber Problem Deadlock Barber The barber has just finished cutting the hair of a customer. He checks if someone is waiting. Customer At the same time, a customer comes and checks if the barber is sleeping. Because the barber is not sleeping, the customer will wait until the barber comes to check. The barber sees that there is nobody in the waiting room, he starts to sleep. There is a deadlock.
6.4 Scheduling: Ostrich Algorithm a. Explain why most operating systems ignore the possibility of deadlock rather than try to prevent this condition or detect and automatically recover from it. Because deadlock avoidance is very time consuming and resource intensive. Deadlock avoidance would also imply restriction on resources (only on file open at any moment or similar things) which would annoy the user a lot more than occasional deadlocks.
6.4 Scheduling: Ostrich Algorithm b. Most message communication between the processes of the operating system Minix are of the type rendezvous. Explain: 1. How this type of communication can lead to a deadlock This mechanism is based on the concept of sending and receiving messages. It eliminates the buffers storing messages. If a process sends a message to another process that did not call the Receive method, then the sending process is blocked until the receive operation is invoked. In the event that a process loop is formed, the risk of deadlock can occur.
6.4 Scheduling: Ostrich Algorithm 2. How Minix prevent these deadlocks. MINIX requires that the sending of messages can only be made to processes on the right or in the lower layers of the model in MINIX. And the loops are no longer possible.
Hints on Implementing PrioServe 1. Identifying the server process The server process is a normal user process, but we want to give it a special priority. Solution: Add a global variable to glo.h. When making the system call, try to get the PID of the server and keep it in the global variable. When scheduling, check the PID of processes. If it is the server, schedule it to a higher priority queue.
Hints on Implementing PrioServe 2. Change the default queue for user processes. kernel/proc.h USER_Q
Hints on Implementing PrioServe 3. Lower the priority of all queues except the server. kernel/proc.c and / or
Remarks There are a lot of possible implementations. It is your job to work out your solution. Please use these hints critically. Read carefully, again, the Minix book 2.5.4, 2.6.5 and 2.6.10! Also read the source code! You may study from the projects of previous years. But do not copy. The scheduling policy for this year is mostly different.