这个死锁问题答案背后的逻辑是什么?

What is the logic behind this deadlock problem answer?

我必须解决这个问题:

Two processes, A and B, each need three records, 1, 2, and 3, in a database. If A asks for them in the order 1, 2, 3, and B asks for them in the same order, deadlock is not possible. However, if B asks for them in the order 3, 2, 1, then deadlock is possible. With three resources, there are 3! or six possible combinations in which each process can request them. What fraction of all the combinations is guaranteed to be deadlock free?

而且我在一本书中看到了解决这个问题的方法:

123 deadlock free
132 deadlock free
213 possible deadlock
231 possible deadlock
312 possible deadlock
321 possible deadlock

Since four of the six may lead to deadlock, there is a 1/3 chance of avoiding a deadlock and a 2/3 chance of getting one.

但我无法弄清楚这个解决方案背后的逻辑。
有人可以解释为什么这个解决方案是正确的吗?
我搜索了很多但没有找到任何东西,而且这个问题的所有答案都没有明确的解释。

当两个线程都必须等待获取另一个线程已经获取的锁(导致两个线程永远等待)时,就会发生死锁。

如果两个线程都先尝试获取同一个锁,那么只有一个线程可以成功,另一个线程必须等待,而等待的线程将在不持有任何锁的情况下等待,因此不会发生死锁,因为线程获得的锁 1 将能够获得它想要的所有其他锁,并且能够在完成时释放锁 1(这允许等待线程继续)。

例如如果 A 和 B 尝试首先获取锁 1 并且 A 获胜,则 B 等待但不持有任何锁,并且 A 可以按它想要的任何顺序获取任何其他锁,因为 B 没有持有任何锁(然后 A 将释放锁 1 B可以停止等待)。