A. The program prints �ABBCAD� B. The program prints �CDDACB� C. The program prints �ADCBADBC� D. The output is a non-deterministic point because of a possible deadlock condition. E. The output is dependent on the threading model of the system the program is running on. The answer is B,D. But I don't know why the B is correct when D is correct. In D, it said it is non-deterministic the print out sequence. Anyone would explain it? thx.
This situation should be recognized visually as a possible deadlock: aThread grabs lock1 aThread grabs lock2 anotherThread grabs lock2 anotherThread grabs lock1 That is, several threads are locking the same locks in different order. The deadlock could occur if: aThread grabs lock1 and anotherThread is scheduled before it can grab lock2. anotherThread grabs lock2 but it cannot continue because lock1 is owned by aThread, thus it blocks waiting for lock1 tob released. Now aThread is scheduled again and tries to get lock2, but it blocks because it is already hold by anotherThread. Both threads are blocked waiting for each other to release the locks. Both threads are blocked without hope to progress.