I
Ian
Hi all,
I have a question regarding the Java tutorial, concurrency trail, which
contains an example of deadlock between two bowing friends.
http://download.oracle.com/javase/tutorial/essential/concurrency/deadlock.html
There is a forum question on this subject, but I don't believe the OPs
question is answered properly:
http://forums.oracle.com/forums/thread.jspa?threadID=1140695&tstart=120.
I have observed the same results as the OP, but I can't reconcile what
happens with any of the tutorial material (the code is pretty much
posted into the tutorial without detailed comment). Is anyone here
familiar with that code?
As far as I can tell, alphonse's thread (by this I mean the first one)
grabs the default monitor for the synchronized bow method, and gaston's
thread (ie the second one) should be blocked, so how does gaston's
thread acquire the lock at all?
I believe that alphonse should therefore be able to bow back, and
release the lock for gaston, but there seems to be a timing window that
allow both to acquire the same lock simultaneously - impossible?
BTW I have altered the deadlock code so that the two methods use
synchronized blocks against different monitors, and the code works fine,
so I am certain that both threads must be holding the same lock. Also,
debugging causes the original program to run as I would expect.
Can anyone enlighten me, I'm sure I'm missing out on something
fundamental here . . .
Hope this is all understandable, Ian.
PS no I don't care how it would be done in c++
I have a question regarding the Java tutorial, concurrency trail, which
contains an example of deadlock between two bowing friends.
http://download.oracle.com/javase/tutorial/essential/concurrency/deadlock.html
There is a forum question on this subject, but I don't believe the OPs
question is answered properly:
http://forums.oracle.com/forums/thread.jspa?threadID=1140695&tstart=120.
I have observed the same results as the OP, but I can't reconcile what
happens with any of the tutorial material (the code is pretty much
posted into the tutorial without detailed comment). Is anyone here
familiar with that code?
As far as I can tell, alphonse's thread (by this I mean the first one)
grabs the default monitor for the synchronized bow method, and gaston's
thread (ie the second one) should be blocked, so how does gaston's
thread acquire the lock at all?
I believe that alphonse should therefore be able to bow back, and
release the lock for gaston, but there seems to be a timing window that
allow both to acquire the same lock simultaneously - impossible?
BTW I have altered the deadlock code so that the two methods use
synchronized blocks against different monitors, and the code works fine,
so I am certain that both threads must be holding the same lock. Also,
debugging causes the original program to run as I would expect.
Can anyone enlighten me, I'm sure I'm missing out on something
fundamental here . . .
Hope this is all understandable, Ian.
PS no I don't care how it would be done in c++