Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer the following questions in complete sentences. Answers should be a

ID: 3878207 • Letter: P

Question

Please answer the following questions in complete sentences. Answers should be about 150 words.

10. Describe the dining-philosophers problem, and explain how it relates to operating systems. (6 marks)

11. Define the two-phase locking protocol. (6 marks)

12. Describe how an adaptive mutex functions. (6 marks)

13. Describe a scenario in which the use of a reader-writer lock is more appropriate than using another synchronization tool, such as a semaphore. (6 marks)

14. What is the difference between deadlock prevention and deadlock avoidance? (6 marks)

15. Describe a wait-for graph, and explain how it detects deadlock. (6 marks)

16. Describe how a safe state ensures that deadlock will be avoided. (6 marks)

Explanation / Answer

Answer:

As per the guidelines we are not allowed to solve more than 1 question but I will try to answer as much as possible, please hit the thumbs up button.

10)

Dining Philosophers:

• N philosophers are seated around a circular table
• There is one chopstick between each philosopher
• A philosopher must pick up its two nearest chopsticks in order to eat
• A philosopher must pick up first one chopstick, then the second one, not both at once
• chopsticks are like resources.
• While a philosopher is holding a chopstick, another one can not have it.

A Condition when semaphore is used but a deadlock condition might arise:

One semaphore per chopstick:
– chopstick: array[0..4] of semaphores
– Initialization:
chopstick[i].count:=1 for i:=0..4

Process Pi:
repeat
think;
//obtain the two chopsticks to immediate right and left
wait(chopstick[i]);
wait(chopstick[i+1 mod 5]);
eat;
/// release both chopsticks
signal(chopstick[i+1 mod 5]);
signal(chopstick[i]);
forever

This condition can lead to deadlock if each philosopher start by picking his left chopstic.

There are three condition variables which should be used in order to solve this problem. There are three states in which we may find a philosopher. Thinking, Hungry and Eating.

Thinking: When philosopher doesn't want to eat. i.e. process doesn't want to gain access to either fork.

Hungry: When the philosopher wants to eat. i.e. the process wants to enter the critical section.

Eating:  When the philosopher is eating. i.e. process has entered the section.

-> (a) Signal: The signal operation simply increments the semaphore variable by 1 which in turn allows another process to check for the condition for getting into the critical section.

Wait: This is used by a process when it enters into the critical section, which decrements the semaphore variable by 1 and stops the entry of any other process while it is its critical section.

e.g. : wait(Semaphore S)

->(b) Signal: The signal operation simply increments the semaphore variable by 1 which in turn allows another process to check for the condition for getting into the critical section.

Continue: Continue is a statement which enforces the next iteration and stops the execution of part of program or code written below it.

11)

Two-phase locking protocol:

Two-phase locking schema is one of the locking schemas in which a transaction cannot request a new lock until it unlocks the operations in the transaction. It is involved in two phases.

Please provide your valuable feedback.