known synchronized() failures?
Thomas Aeby
aeby@graeff.com
Wed Apr 27 10:28:00 GMT 2005
The last few days I spent on debuggin a really unpleasant problem. One
of my programs making extensive use of locks ("synchronized") is
reproducibly hanging after a while of operation. After quite some
debugging I'm sure that it is hanging at the start of a synchronized()
block:
Vector jobqueue = ...
...
while( doagain )
mythread.setName( "Loop" );
synchronized( jobqueue ) {
mythread.setName( "Loop" );
....
}
The intention is to process a queue within a loop, and each loop give
up the lock so that other threads get a chance to get the jobqueue
lock, too. Obviously, this thread is hanging sometimes at the beginning
of the synchronized() block, thus when printing out the names of the
existing Threads the thread prints as "Loop", the pstack utility tells
me the same. Just some deadlock in my code, you are telling me? Read
on :-)
At the time the synchronized() hangs another thread (the one holding
the lock at that moment) hangs at the end of a similiar synchronized()
block.
The thread hanging at the start of the block consumes 100% CPU,
therefore must be in some busy-waiting loop????
Both this observations tell me that this is not a bug in my Java
code since one thread is about to give up a lock while the other is
trying to claim the same lock - so no deadlock.
Unfortunately, I haven't been able to write a testcase showing the
same misbehaviour, it's probably just some race condition that is
not easy to reproduce.
I've tested GCJ 3.3.5 and 3.4.4 (Debian).
Has anyone made the same observations, is the problem known and does
anyone know a workaround or a solution for this? synchronized() not
working reliable looks like a serious problem to me since it's commonly
used throughout any Java code including libgcj ...
Thank you very much for any hint.
Best regards,
Tom
--
----------------------------------------------------------------------------
Thomas Aeby, Kirchweg 52, 1735 Giffers, Switzerland, Tel: (+41)264180040
Internet: aeby@graeff.com PGP public key available
----------------------------------------------------------------------------
More information about the Java
mailing list