previous | start | next

Example Preventing Deadlock

We could specify a protocol of how the objects must be locked.

E.g., If a thread wants to use both objects at the same time, it must lock object 1 first and then object 2.

Suppose thread 1 has object 1, but is not using object 2.

If thread 2 wants to use both objects, it shouldn't lock object 2 even though it is free. It should (try) to lock object 1 (and will block until it is released.)

If there are more than 2 objects, extending this to an ordering will also work to prevent deadlock.



previous | start | next