How about this:  Could we send all daemon threads hardware exceptions after joinAll()?  In the vast majority of cases, locks will be scoped, either through synchronized blocks or simple scope(exit) mutex.unlock() type statements.  If they're not then they should be.  (If any still aren't in std.parallelism then I'll fix this.  I originally made a few non-scoped around code that couldn't throw, but this was silly and I think I changed all of them.)  This way daemon threads terminate immediately, locks get released if the code's well-written, <br>
and if you **really** need to do some cleanup, you can catch the exception.<br><br><div class="gmail_quote">On Wed, Sep 14, 2011 at 1:04 AM, Sean Kelly <span dir="ltr"><<a href="mailto:sean@invisibleduck.org">sean@invisibleduck.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Sep 13, 2011, at 11:59 AM, Martin Nowak wrote:<br>
<br>
> I've had a look the core dumps from the sometimes failing std.parallelism test.<br>
> The issue is one of having daemon threads running while the GC is unmapping memory.<br>
> Usually this goes unnoticed because the parallelism threads wait in a work queue condition.<br>
> Sometimes a daemon thread is awakening from it's GC suspend handler after memory was already<br>
> freed. This issue is already mentioned in a comment at gc_term.<br>
><br>
><br>
> Thread  obj = Thread.getThis();<br>
><br>
> ...<br>
> suspend<br>
> ...<br>
><br>
> if( obj && !obj.m_lock ) // <- segfault<br>
><br>
><br>
> I think we should bluntly kill daemon threads after thread_joinAll.<br>
<br>
</div>One issue with this is that if these threads held any locks accessed during later parts of the cleanup (the GC lock, module-level locks accessed in static dtors, etc), the app could hang instead of shutting down cleanly.  If the threads are forcibly terminated then it would really have to be after these cleanup steps occurred, but by then Bad Things could already be happening because module dtors have been run and the GC is terminated.<br>

<br>
Since daemon threads are an explicit choice made by the user, I hope that they have also considered how to notify them to terminate cleanly (as one does in C/C++ where daemon threads are the default).  The best thing is really to build this into the relevant module dtor.  There's also Runtime.isHalting if someone can present a case to un-deprecate it.<br>

<div><div></div><div class="h5">_______________________________________________<br>
phobos mailing list<br>
<a href="mailto:phobos@puremagic.com">phobos@puremagic.com</a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/phobos" target="_blank">http://lists.puremagic.com/mailman/listinfo/phobos</a><br>
</div></div></blockquote></div><br>