paulmac1968 wrote:I'm not sure what you mean. Do you have a simple example?
Process P1 locks resource R1, uses it, and unlocks it, then R2; process P2 locks R2, then R1.
They attempt to do this:
P1 P2
=== ===
Lock R1
Lock R2
Lock R2 (can't, because P2 has it locked)
Lock R1 (can't, because P1 has it locked)
Deadlock, right?
Now consider changes to P2 so that it uses the resources in the same order as P1:
P1 P2
=== ===
Lock R1
Lock R1 (Can't, because P1 has it locked)
Unlock R1
Lock R2
Lock R1 (Now works, because P1 no longer has it locked)
Unlock R2
EOJ Lock R2
Unlock R2
EOJ
No dead lock, right?
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day