Chapter 2 Tanenbaum-Pearce 6
Chapter 2 Tanenbaum-Pearce 6
)
ANDREW S. TANENBAUM Modified by S. Pearce
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
NOTE: The Producer-Consumer Problem of Processes and Threads 4 introduced the issues that are fundamental to IPC, and is often regarded as so-called classical.
Wikipedia
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
QUESTION: Can each philosophers indefinitely perform the task of thinking without starving according to this simple set of rules?
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Simple-Minded Solution
Simple-Minded Solution
Think until the left fork is available; when it is, pick it up Think until the right fork is available; when it is, pick it up Eat Put the left fork down Put the right fork down Repeat from the start
Simple-Minded Solution
Think until the left fork is available; when it is, pick it up Think until the right fork is available; when it is, pick it up Eat Put the left fork down Put the right fork down Repeat from the start
The following possibility exists: Each philosopher holds one LH-chopstick, waiting for the RHchopstick to be relinquished - DEADLOCK.
QUESTION: Can each philosophers indefinitely perform the task of thinking without starving according to this simple set of rules? TWO MORE RULES: 5. It is impossible for deadlock to occur.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
QUESTION: Can each philosophers indefinitely perform the task of thinking without starving according to this simple set of rules? TWO MORE RULES: 5. It is impossible for deadlock to occur. 6. It is impossible for starvation to occur.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Example 1: One semaphore per philosopher ensuring that only one philosopher can pick up a chopstick at any time. This fails if all philosophers put their LH chopstick down simultaneously (context switching occurs after down and so all of them will just sit there indefinitely with a LH chopstick in their hands).
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Example 2: Use a single MUTEX semaphore enforcing the rule that only one philosopher can pick up a chopstick at any given time. The result removes starvation, but only one philosopher can eat at a time wasteful.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 2-46. A deadlock-free solution for N dining philosophers, utilizing the array, state, to keep track of semaphores such that hungry philosophers can block if needed forks are busy.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
END
PRESENTATION