Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Deadlock  RSS feed

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How this code can be deadlock?



Method a() can run easily
it calls method b()....

How can it be deadlock?

 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure it can't create a deadlock. Certainly not by itself. Did someone tell you there was a problem? You probably need to ask them what they meant. And consider the possibility that they are simply wrong.
 
abhay bansal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea this can not result into a deadlock else it will defeat the whole reentrant locking mechanism.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you show me how to use JVM thread dump to find deadlock?

I mean a please instance very simple program that has deadlock , extract its thread dump and point how to use thread dump of that code to find deadlock

Thanks in advance.
 
Rok Ć telcer
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Why not use the one from Sun's tutorial: Deadlock Example?

Compile and and run the program.
After the following two messages appear:
"Alphonse: Gaston has bowed to me!"
"Gaston: Alphonse has bowed to me!",
press the following key sequence in the cmd/shell:
- CTRL + break (Win)
- CTRL + '\' (Unix)

You'll receive a thread dump.
Following is just a snip with a deadlock msg:
...
Found one Java-level deadlock:
=============================
"Thread-1":
waiting to lock monitor 0x01664624 (object 0x23701150, a Deadlock$Friend),
which is held by "Thread-0"
"Thread-0":
waiting to lock monitor 0x01665e84 (object 0x23701160, a Deadlock$Friend),
which is held by "Thread-1"

Java stack information for the threads listed above:
===================================================
"Thread-1":
at Deadlock$Friend.bowBack(Deadlock.java:16)
- waiting to lock <0x23701150> (a Deadlock$Friend)
at Deadlock$Friend.bow(Deadlock.java:13)
- locked <0x23701160> (a Deadlock$Friend)
at Deadlock$2.run(Deadlock.java:28)
at java.lang.Thread.run(Unknown Source)
"Thread-0":
at Deadlock$Friend.bowBack(Deadlock.java:16)
- waiting to lock <0x23701160> (a Deadlock$Friend)
at Deadlock$Friend.bow(Deadlock.java:13)
- locked <0x23701150> (a Deadlock$Friend)
at Deadlock$1.run(Deadlock.java:25)
at java.lang.Thread.run(Unknown Source)

Found 1 deadlock.
...

Hope this helps.


Regards,
Rok
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!