<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jan 20, 2010, at 1:00 PM, Andrei Alexandrescu wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Michel Fortin wrote:<br><blockquote type="cite">Le 2010-01-20 à 15:24, Andrei Alexandrescu a écrit :<br></blockquote><blockquote type="cite"><blockquote type="cite">I think threads shouldn't be able to do much during shutdown. For example I don't think they should suddenly open sockets. How about opening files? Or calling system()? Any ideas on a unified approach?<br></blockquote></blockquote><blockquote type="cite">Why do you think that?<br></blockquote><br>I'm thinking, there are too many programs that hang when I want to end them just because some thread inside is waiting for a socket. I think that any operation that could block for an arbitrary amount of time should be disallowed during shutdown.<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><div><br></div>What if the program is logging to a remote host and wants to log a shutdown event?</div><div><br><blockquote type="cite"><div>What sockets library do today is, they offer a global close_library function. Once that is called, all pending socket connections and all new socket connections fail immediately.<br></div></blockquote></div><br><div>If it helps, here is the current process shutdown behavior:</div><div><br></div><div>1. join all non-daemon threads (non-daemon is the default)</div><div>2. set Runtime.isHalting to true</div><div>3. call module dtors</div><div>4. cleanup and exit</div><div><br></div><div>What's missing here is that daemon threads are forcibly terminated when the process exits, while following the shotdown approach there should be a step 3a that causes messaging to throw, etc. Instead of setting an isDaemon flag in user code, some other means could be used. Perhaps calling detach() on a Tid makes the thread a daemon thread?</div></body></html>