# Deadlock and safe state

I read that system being in safe state doesn't guarantee that deadlock is not possible.

Can someone give me an example where system is in safe state and deadlock is possible?

• Where did you read that? What specifically did they say? What definition of 'safe state' are you using? – D.W. Jul 30 '17 at 23:05
• I guess you got confuse for the safe state definition. Safe state means the safe sequence of process s.t. allocation of resources in this order will not result in deadlock. Although unsafe state doesn't always mean that the system will result into deadlock. – Pragya Jul 31 '17 at 9:16
• I read that even if the system is in safe state, then there can be some another execution sequence which can lead to deadlock. – Zephyr Jul 31 '17 at 12:53
• @Zephyr There are 2 units of resource A and 2 units of resource B. Job $j$ requires 2 As and 1 B. Job $k$ requires 1 A and 2Bs. System is in safe state since we can run $j$ to the end, after which we can run $k$ to the end. However, if 1 A and 1 B is assigned to $i$ while 1A and 1B is also assigned to $k$, here comes the deadlock. – Apass.Jack Mar 12 at 0:38

## 1 Answer

That is not possible, when a deadlock occurs, the system is in an UNSAFE state. A safe state wouldn't have any purpose if a deadlock could occur.

• Please check my comment here. Although system is safe, a deadlock would occur if the following operations are not safe, as shown by my example. Of course, we can run a system at a safe state to another safe state if we want to. – Apass.Jack Mar 12 at 17:23
• I understand your example, but the following operations have to be done in order that a deadlock can occur. A safe state is a setting where it is guaranteed to be deadlock-free. (without doing any operations ofcourse) – NimaKimi Mar 12 at 21:06
• We are saying the two sides of exactly the same thing. You are saying the part of definition that deadlock is not happening right now. I am emphasizing that deadlock might happen in the future. It occurs to me that "deadlock is possible" refers to future. However, it could mean "deadlock might be possible right now", which is false as you pointed out. – Apass.Jack Mar 12 at 23:20