Kagamin Wrote:

> Andrei Alexandrescu Wrote:
> 
> > Terminating threads has always been iffy in all languages that use 
> > native threads. I've discussed with Sean a couple of times about ways to 
> > define a little protocol and API for orderly thread termination. We need 
> > something like a callback mechanism - atShutdown().
> 
> Why? Just call delete on the thread object and in destructor do everything 
> you want to put in atShutdown.

Thread objects are tracked by the runtime.  If you explicitly delete them, 
expect a segfault.  I suppose I could use a pimpl approach to avoid this, but 
it would be a tad tricky (Thread.getThis() for example).  More appropriate is 
to use a non-shared static dtor to signal thread shutdown, which is basically 
how OwnerTerminated works anyway.  It's just taken care of for you.

Reply via email to