Consider a traffic deadlock as in the following picture:
a) Show that the four necessary conditions for deadlock indeed hold in this example.
The four conditions necessary for deadlock to be possible are:
mutual exclusion - only one car can occupy each intersection at a time
hold and wait - cars can hold an intersection while waiting in a line for access to the next intersection
no preemption - cars cannot be removed from their spot in the traffic flow, except by moving forward
circular wait - the set of cars in the deadlock situation includes the cars in the middle of the intersection
b) State a simple rule that will avoid deadlocks in this system.
Install traffic lights that only allow flow in one direction or the other at a time.
You can still envision a possible deadlock if a city block is completely full of cars turning left or right. I think you'd need to add a criteria to the problem requiring that cars will eventually leave the city block as well to prevent this.