Daemon ThreadGroups don't work properly.

Project:JNode Core
Component:Code
Category:bug report
Priority:normal
Assigned:Stephen Crawley
Status:closed
Description

It seems that the JNode implementation of the 'daemon' flag for ThreadGroup is wrong. In the GNU Classpath codebase (on Savannah), a daemon ThreadGroup is destroyed when it has no remaining active threads and no remaining child ThreadGroups. I've yet to fully test this but my initial black-box testing against the Sun 1.6 implementation confirm this.

By contrast, the JNode version deletes a daemon ThreadGroup only when the last Thread exits as a result of a Thread.stop() call. This seems to be based on a literal reading of the Sun javadocs ... but the javadocs are not definitive. Anyway, the current behaviour of daemon ThreadGroups on JNode makes them next to useless.

I'm working up a complete testcase, and will check it in in due course.

#1

Status:active» closed

Confirmed. The attached testcase runs all 3 tests without errors on Sun JDK 1.6 but fails in the 2nd and 3rd ones on JNode.

#2

The problem was that the Thread implementation was calling add(Thread) rather than addUnstarted() on a new Thread object's ThreadGroup. This caused the ThreadGroup's 'nUnstartedThreads' count to go negative, and the later call to remove(Thread) not destroying the (daemon) ThreadGroup.

I've checked in the testcase (with a minor fix) and a bug fix to Thread.java. The SVN revision number for the bug fix is 4028.