classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Joining all non-daemon threads


From: Bryce McKinlay
Subject: Re: Joining all non-daemon threads
Date: Tue, 18 Sep 2001 20:00:48 +1200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) Gecko/20010913

Tom Tromey wrote:

"Patrick" == Patrick Doyle <address@hidden> writes:


Patrick> What's the easiest way to implement this?  Does ThreadGroup
Patrick> provide enough functionality to do it?  Or do I have to
Patrick> maintain a list of active threads myself?  Does Classpath
Patrick> have any additional functionality to support this?

In libgcj we have a master thread which simply waits on a condition
variable.  When a new thread is started, an active thread count is
incremented.  When a thread dies, the count is decremented and the
master thread is notified.  If it finds that the count is zero, the VM
shuts down.
An alternate technique would be to simply have each non-daemon check the counter as it exits. If its 0 (after decrementing for itself) then call Runtime.exit().

Recently in libgcj we made the "master" thread actually the "main" thread as well - first it runs main() then it sits waiting for other non-daemons to exit. See _Jv_RunMain() in libjava/prims.cc.

In our implementation ThreadGroup doesn't enter the
picture.
There is a special case where we want to exit the runtime with an error status if a thread threw an uncaught exception. We look at threadgroup.had_uncaught_exception to determine that.

regards

Bryce.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]