I was reading Operating Systems by Galvin and came across the below line,
Not all unsafe states are deadlock, however. An unsafe state may lead to deadlock
Can someone please explain how deadlock != unsafe state ? I also caught the same line here
If a safe sequence does not exist, then the system is in an unsafe state, which MAY lead to deadlock. ( All safe states are deadlock free, but not all unsafe states lead to deadlocks. )
Asked By : vikkyhacks
Answered By : Wandering Logic
Deadlock means something specific: there are two (or more) processes that are currently blocked waiting for each other.
In an unsafe state you can also be in a situation where there might be a deadlock sometime in the future, but it hasn't happened yet because one or both of the processes haven't actually started waiting.
Consider the following example:
Process A Process B lock X lock Y # state is "unsafe" unlock Y lock Y # state is back to "safe" (no deadlock this time. We got lucky.)
There's a more interesting example in Section 7.5.1 of the link you gave:
Consider a system with 12 tape drives with:
Process Max Need Current P0: 10 5 P2: 9 3
This is an unsafe state. But we're not in a deadlock. There's only 4 free drives, so, for example, if P0 does request an additional 5, and P2 does request an additional 1, we will deadlock, but it hasn't happened yet. And P0 might not request any more drives, but might instead free up the drives it already has. The Max need
is over all possible executions of the program, and this might not be one of the executions where we need all 10 drives in P0.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/45145
0 comments:
Post a Comment
Let us know your responses and feedback