Suppose I have a system with N processes. Each process needs max K resources (K << N). To prevent collisions a process needs to lock each resource before accessing it. Is a deadlock possible and if yes, what is the maximum N for which the system is still deadlock free?
Best How To :
The maximum N is 1. with 2 or more threads interacting in the same process with the same memory, a deadlock is entirely possible. Scenario:
A asks for and receives lock 1
B asks for and receives lock 2
A asks for lock 2 and pauses
B asks for lock 1 and pauses
A and B now deadlock
The order of locking must be consistent for > 1 locks in order to fully prevent deadlocks.