Question: Write a C program to simulate thread scheduling that ensures deadlock avoidance using a simplified resource allocation system. The goal is to avoid deadlock by
Write a C program to simulate thread scheduling that ensures deadlock avoidance using a simplified resource allocation system. The goal is to avoid deadlock by controlling the order in which threads acquire locks, based on a predefined global knowledge of resources.
Design:
You should create threads T T T and each thread needs to acquire locks Lock A and Lock B in a specific order.
The threads should not be able to acquire locks in a fashion such that the program deadlocks.
The program should ensure deadlockfree execution by scheduling the acquisition of locks based on the given deadlock avoidance algorithm.
Implement deadlock avoidance using Resource Instance Ordering as follows:
Enforce a strict lock acquisition order eg Lock A must always be acquired before Lock B
Input:
None
Output:
Print messages showing the order of lock acquisition and thread waiting egT acquired Lock AT waiting for Lock A
The program should terminate after each thread has acquired each lock times.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
