When a Thread Terminates

I’m still dealing with this deadlock problem. In some cases, the following might happen: Thread 1 enters compactWait, but finds out thread 2 is waiting for this synchronization point. Thread 2 wakes thread 1 up and waits for the next synchronization point. Thread 1 terminates, and thread 2 never gets woken up.

What I should try is insert a call to compactWait (or some other method, maybe compactEndThread) at the very end of java.lang.Thread.exit. I’m hoping that this will actually be at the end of a thread’s life, and there won’t be any more sync points afterwards. Otherwise, this is not going to work.

This call will check if there is a thread waiting to be woken up at the current index, and if so, wake it up. Otherwise, it’s a no-op, because there should be a thread running already, about to enter compactWait and execute.

If this doesn’t work, e.g. because there are still sync points happening after java.lang.Thread.exit, then I could try some kind of “counting scheme”. I count the number of threads alive and how many of them are currently waiting. If the second number ever becomes equal to the first number, I’d have to wake a thread up. But that seems more complicated right now.

I don’t feel too well right now – felt awful yesterday, too – but I have a date. Time for dinner and a movie.

Share

About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in Concurrent Unit Testing. Bookmark the permalink.

Leave a Reply