A deadlock is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does.
A program probably causes deadlock between two threads that are both trying to acquire locks for the same two resources.
To avoid this sort of deadlock when locking multiple resources, all threads should always acquire their locks in the same order.
Thread 1 locked resource1, and won't release it 'till it gets a lock on
resource2. This thread2 holds the lock on resource2, and won't
release it 'till it gets resource1. We're at an impasse. Neither thread can run, and the program freezes up.
A program probably causes deadlock between two threads that are both trying to acquire locks for the same two resources.
To avoid this sort of deadlock when locking multiple resources, all threads should always acquire their locks in the same order.
Thread 1 locked resource1, and won't release it 'till it gets a lock on
resource2. This thread2 holds the lock on resource2, and won't
release it 'till it gets resource1. We're at an impasse. Neither thread can run, and the program freezes up.