About topic
Know About topic
Deadlock Algorithms
Banker's Algorithm
-
Banker's Algorithm
Banker’s algorithm is named so because it is used in banking system to check whether loan can be sanctioned to a person or not. The bank would never allocate its money in such a way that it can no longer satisfy the needs of all its customers. The bank would try to be in safe state always.
-
Safety Algorithm:
This algorithm is used to find out if the system is in a safe state. A safe state is a state where all the pending processes can be executed without leading to a deadlock of resources.
-
Resource Requesting Algorithm
This algorithm is used to determine if the request of a program to allocate more resources should be granted. Here we simulate the granting of resources and then check if system is in safe state using the safety algorithm. Only if it is in a safe state we allocate resources.
-
The Simulation
First the number of programs and the number of resources are specified. Then the respective fields for each program must be filled. The allocation and need values are automatically entered into the table. After entering all values, the user can click either the safety algorithm, which tells if the system is in a safe state or the resource allocation algorithm which calculates whether the request of a program for resource can be made without resulting in deadlock.
Dining Philosopher's Algorithm
-
What is the Dining Philosopher's problem?
The Dining Philosopher Problem states that K philosophers seated around a circular table with one chopstick between each pair of philosophers. There is one chopstick between each philosopher. A philosopher may eat if he can pick up the two chopsticks adjacent to him. One chopstick may be picked up by any one of its adjacent followers but not both.
-
The states of a philosopher
A Philosopher can have 3 states: Think, Hungry and Eat. A thinking philosopher may become hungry and at that time if both chopsticks are available, the philospher will go to the eating state. After eating, the philosopher is back to the thinking state.
-
How is this related to deadlock prevention?
Dining Philosophers problem represents a possible deadlock scenario. If all philosophers take one chopstick then the system is in a deeadlock. The algorithm can prevent this in 3 ways: Either all philosophers should not be allowed to eat first or a philosopher has to take both chopsticks. He/she can't take only one. The third way is to allocate the first chopstick to the last philosopher instead of the first so that way the last philosopher can always complete eating and release the resources and deadlock is prevented.
-
The Simulation
The simulation has an option to set the number of philosophers and also the simulation speed. Once the page has loaded, the simulation will automatically start in 3 seconds. Each philosopher acts independently and randomly enters into think, hungry and eat states. The dining philosophers algorithm tries to prevent deadlock in the background by making a philosopher to always take both chopsticks instead of one. Note: A reset button has been included since due to certain characteristics of asynchronous functions in react the simulation might be stuck in an error.
F.A.Q
Frequently Asked Questions
Questions related to system security
-
What is safe state?
A safe state is a state where all processes can be executed with the available resources. i.e no deadlock. The safety sequence is this order of process execution
-
What is deadlock?
Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process.
-
How to prevent deadlocks?
This is essentially where bankers algorithm comes in. When a process makes a request for resource allocation, it always checks if it will lead to a deadlock. If it doesn't, the request is granted else the process is made to wait
-
What happens if there is a deadlock?
If there is a deadlock, i.e each process is waiting for resources held by the other process, then process execution comes to a stand still and computer becomes unresonsive.