More useful Deadlock message ?

The deadlock message is a good thing but I would like to have more informations.

Ideally, the message give the 2 lines (for notify and for wait) in the source code.
Or at least, the class where is the deadlock (I think notify and for wait are generally in the same class).

Do you have any idea ?

Having more informations will be useful for debuging and removing deadlocks.

Now, I see lots of deadlock while I do a dir on the root. This involve timeouts and strange result due to these timeouts.

What do you think of throwing DeadlockException ... ?

What do you think of throwing a DeadlockException when a thread is doing something that will create a Deadlock ?
This way we have a good help to find the source code location of a Deadlock.

In VmThread.walkWaitingThread, there is a detection algorithm (called by the idle thread) that identify thread already deadlocked.

I used this algorithm in MonitorManager.wait in order to detect a deadlock before it come and throw a DeadlockException. The problem is that during JNode boot I have a lot of Deadlock.
Moreover, when the shell is waiting for a key, deadlock are continuously detected.
I don't know if they are false alerts or if they are true deadlocks that are usefull. If they are usefull, I need a filter to know what is a usefull deadlock and what is not.

However, I know that (bad or all) deadlocks must be removed from code. But, I think we need something like this for debug purpose.

Exception?

IMHO, the problem is that when two or more thread are in deadlock none of of them can throw an exception because they are waiting. The excpetion can only be thrown by the thread that is detects the deadlock. However is this thread throws an exception then it risk to should down itself and on the other hand the stacktrace would refer to the deadock detection code hance telling nothing about the cause of teh deadlock. If you would like to get more info about the dealock you could expect from this thread to enumerate the thread that are in dealock and print their stacktraces. At least that would show where the respective thread are waiting in the deadlock. This has the drawback that if deadlock are frequent you would see plenty of stacktracaes all the time and not much from anything else.
The thread syncronization is a really tricky thing. I'm affraid we will fight a lot with this one.
Did you try to use the debugger to find out more about a deadlock, does it help?

Levente

DeadlockException thrown just before the deadlock

I throw the DeadlockException just before the deadlock occure (inside the wait method).
So the deadlock has been avoided, and instead we have the stack trace (printed by an exception handler) of the thread that tried to create a deadlock.

good idea

hi,
I think its a good idea...

Andreas