Deadlock

  • 4
  • Locked
1. Figure out how the program works. 2. Without changing the T1 and T2 classes, make it so their threads finish (not necessarily successfully). 3. Don't use the sleep method.
You can't complete this task, because you're not signed in.
Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
aijo
Level 30 , Germany, Germany
12 February 2022, 10:06
The code below allows both threads to finish (and is accepted as a solution to this task) - could anyone please help me understand why? Is t2.join() in T1 immediately satisfied because t2 was not yet started? If so, then I avoided the deadlock by making the threads work sequentially...which shouldn't be really accepted as a correct solution, I think. But I'm just guessing here :)
t1.start();
t1.join();
t2.start();