• Post Reply Bookmark Topic Watch Topic
  • New Topic

why deadlock?  RSS feed

 
Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


1. when first thread invokes alphonse.bow(gaston), what lock would be used for bow() in this call? I'm assuming it will be alphonse object. I'm guessing the same also applies for invocation of gaston.bow(alphonse) where the lock will be gaston.
2. if so, since they're using different locks, deadlock is impossible, so how can this code cause deadlock?
3. first thread will invoke alphonse's bow() and gaston's bowback(), while the second will invoke gaston's bow() and alphonse's bowback(), so there is no same methods being called by different threads, this confirms even more that there's no way a deadlock can happen, right?

thanks
 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
alphonse.bow() and alphonse.bowback() lock on same object, same applies to gaston methods
You can imagine the table has 1 knife and fork.
Person A takes the knife while Person B takes the fork.
They would be dead locked on waiting each other.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!