Tutorial4 - there are empty chairs) or leave the office (if...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Tutorial IV November 8, 2010 Question 1 (2006/07 Examination) Consider using a binary semaphore to implement a solution to the Dining Philosophers. The following is the code segment that implements the philosopher’s behavior: Semaphore sem = 1; typicalPhilosopher( ) { think( ); wait(sem); pickUpLeftFork( ); pickUpRightFork( ); eatingSpaghetti( ); putDownLeftFork( ); pickDownRightFork( ); signal(sem); } Assume we are implementing the semaphore’s wait( ) and signal( ) functions with busy waiting. Comment on this approach with respect to mutual exclusion, deadlock, starvation, and execution performance. Question 2 (2000/01 Examination) The following situation takes place in a dentist office: The dentist office has one dentist, one dental chair, and 5 chairs for waiting patients, if any, to sit in. If there are no patients present, the dentist sits down in the dental chair and takes a rest. When a patient arrives, he notifies the dentist. If additional patients arrive while the dentist is working on a patient’s teeth, they either sit down (if
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: there are empty chairs) or leave the office (if all chairs are occupied). You are asked to do process synchronization using semaphores for the dentist and the patients without getting into race conditions. Define the semaphores and their functions together with their initial values clearly and make detail comments of your program. Question 3 (2006/07 Examination) Assume a system with four resource types (A, B, C, and D) and five processes (p , p 1 , p 2 , p 3 , and p 4 ). There are multiple units of each type of resources. Is the state of the system safe with the following resource allocation information? Explain your answer. If the system is safe, show how all processes could complete their execution successfully. If the system is unsafe, show how deadlock might occur. Total Resources A B C D 6 4 4 2 Maximum Claim Process A B C D p 0 3 2 1 1 p 1 1 2 0 2 p 2 1 1 2 0 p 3 3 2 1 0 p 4 2 1 0 1 Current loan Process A B C D p 0 2 0 1 0 p 1 1 1 0 0 p 2 1 1 0 0 p 3 1 0 1 0 p 4 0 1 0 1...
View Full Document

This note was uploaded on 12/01/2010 for the course CS 2342 taught by Professor Dr during the Spring '10 term at HKU.

Page1 / 2

Tutorial4 - there are empty chairs) or leave the office (if...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online