<br><br><div class="gmail_quote">On Wed, Jan 20, 2010 at 1:39 AM, Sean Kelly <span dir="ltr">&lt;<a href="mailto:sean@invisibleduck.org">sean@invisibleduck.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
void fnB() {<br>
    // do something that takes a while<br>
}<br>
void fnA() {<br></blockquote><div>auto tid = <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
    spawn( &amp;fnB );<br></blockquote><div>tid.wait();<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
}<br>
<br>
void main() {<br>
    auto tid = spawn( &amp;fnA );<br>
    tid.wait();<br>
}<br>
<br>
The main thread doesn&#39;t know the thread running fnB exists so it can&#39;t wait for it, even if it&#39;s doing completely legitimate work and shouldn&#39;t be interrupted.  How can I trivially rewrite this program so it completes without error?<br>

<div><div></div><div class="h5"><br>
On Jan 19, 2010, at 10:28 PM, Andrei Alexandrescu wrote:<br>
<br>
&gt; That would certainly work, but honest to God I am completely infatuated with the proposed model. It&#39;s simple, no need for a new &quot;daemon&quot; concept, and avoids very easily and elegantly the unpleasant zombie situation when main has finished but is somewhere in limbo mode hoping for some other thread to end.<br>

&gt;<br>
&gt; Also, look at how simple it makes all examples. It&#39;s a dream come true. I&#39;ve been thinking of a correct shutdown protocol for years, and this is better than anything I&#39;ve ever tried.<br>
&gt;<br>
&gt; I&#39;d be ok with doing what Java does if we find an Achilles&#39; heel of the current model. If not, I suggest we go with it and let users handle their own daemons (heh) in main().<br>
&gt;<br>
&gt;<br>
&gt; Andrei<br>
&gt;<br>
&gt; Sean Kelly wrote:<br>
&gt;&gt; On Jan 19, 2010, at 9:49 PM, Andrei Alexandrescu wrote:<br>
&gt;&gt;&gt; Sorry, I was unclear on that. Once the application is shutting down, any call to concurrency-related function, pending or new, will result in the Shutdown exception.<br>
&gt;&gt; Why couldn&#39;t any threads that cared simply watch() the main thread so they&#39;ll be notified when it terminates?  Forcing this behavior on the user means that if an app wants to do anything in a separate thread that doesn&#39;t communicate with the main thread, he&#39;d have to make sure the main thread joined every other thread in the process to keep from interrupting it.<br>

&gt;&gt; Druntime follows the Java model of having an isDaemon field on the Thread object.  If isDaemon is false for a thread T1 then the main thread will silently wait for T1 to terminate before shutting down the app.  If isDaemon is true however, T1 will be terminated forcibly by the OS as the process exits.  Perhaps we could provide this ShutdownException behavior only to daemon threads as a replacement for the messy shutdown they have now?<br>

&gt;&gt; _______________________________________________<br>
&gt;&gt; dmd-concurrency mailing list<br>
&gt;&gt; <a href="mailto:dmd-concurrency@puremagic.com">dmd-concurrency@puremagic.com</a><br>
&gt;&gt; <a href="http://lists.puremagic.com/mailman/listinfo/dmd-concurrency" target="_blank">http://lists.puremagic.com/mailman/listinfo/dmd-concurrency</a><br>
&gt; _______________________________________________<br>
&gt; dmd-concurrency mailing list<br>
&gt; <a href="mailto:dmd-concurrency@puremagic.com">dmd-concurrency@puremagic.com</a><br>
&gt; <a href="http://lists.puremagic.com/mailman/listinfo/dmd-concurrency" target="_blank">http://lists.puremagic.com/mailman/listinfo/dmd-concurrency</a><br>
<br>
_______________________________________________<br>
dmd-concurrency mailing list<br>
<a href="mailto:dmd-concurrency@puremagic.com">dmd-concurrency@puremagic.com</a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/dmd-concurrency" target="_blank">http://lists.puremagic.com/mailman/listinfo/dmd-concurrency</a><br>
</div></div></blockquote></div><br>