Another great example. Thank you very much!<div><br></div><div>I had to evaluate the whole thing inside of a [ ... ] fork, in order to see the updates in the Transcript... <br><br><div class="gmail_quote">2012/11/2 David T. Lewis <span dir="ltr">&lt;<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, Nov 02, 2012 at 07:40:08PM +0100, Bert Freudenberg wrote:<br>
&gt; On 2012-11-02, at 19:24, Sebastian Nozzi &lt;<a href="mailto:sebnozzi@gmail.com">sebnozzi@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; Thanks!<br>
&gt; &gt;<br>
&gt; &gt; Didn&#39;t know it was so simple... I was kind of intimidated by &quot;wait&quot;. Thought, well, that it suspended the thread no matter what.<br>
&gt; &gt;<br>
&gt; &gt; Another question, out of curiosity:<br>
&gt; &gt;<br>
&gt; &gt; Is it possible to have one thread wait for 2 other threads to finish? Would it also be solved with Semaphores like this?<br>
&gt; &gt;<br>
&gt; &gt; s1 := Semaphore forMutualExclusion.<br>
&gt; &gt; s2 := Semaphore forMutualExclusion.<br>
&gt; &gt; [ s1 wait. do stuff .... s1 signal] fork.<br>
&gt; &gt; [ s2 wait. do stuff ..... s2 signal ] fork.<br>
&gt; &gt;<br>
&gt; &gt; s1 wait.<br>
&gt; &gt; s2 wait.<br>
&gt; &gt; &quot;Here we are sure the two other processes finished, kind of...&quot;<br>
&gt; &gt;<br>
&gt; &gt; Or is there a more &quot;friendly&quot; way? :-)<br>
&gt; &gt;<br>
&gt; &gt; Thanks again!<br>
&gt; &gt;<br>
&gt; &gt; Sebastian<br>
&gt;<br>
&gt; Looks okay to me. But you could make it a bit simpler:<br>
&gt;<br>
&gt; s1 := Semaphore new.<br>
&gt; s2 := Semaphore new.<br>
&gt; [ do stuff .... s1 signal] fork.<br>
&gt; [ do stuff ..... s2 signal] fork.<br>
&gt; s1 wait.<br>
&gt; s2 wait.<br>
&gt;<br>
&gt; Or even:<br>
&gt;<br>
&gt; s1 := Semaphore new.<br>
&gt; [ do stuff .... s1 signal] fork.<br>
&gt; [ do stuff ..... s1 signal] fork.<br>
&gt; s1 wait; wait.<br>
&gt;<br>
<br>
</div></div>And you can see how this works by writing a few things to the transcript.<br>
Try evaluating this in a workspace:<br>
<br>
   Transcript clear.<br>
   sema := Semaphore new.<br>
   arrayOfFourProcesses := {<br>
        [(Delay forSeconds: 8) wait. sema signal] fork.<br>
        [(Delay forSeconds: 2) wait. sema signal] fork.<br>
        [(Delay forSeconds: 6) wait. sema signal] fork.<br>
        [(Delay forSeconds: 4) wait. sema signal] fork<br>
   }.<br>
   (Delay forMilliseconds: 100) wait. &quot;allow the processes to start&quot;<br>
<br>
   Transcript cr; show: DateAndTime now asString.<br>
   arrayOfFourProcesses do: [:e | Transcript cr; show: e printString].<br>
<br>
   sema wait.<br>
   Transcript cr; cr; show: DateAndTime now asString, &#39; one process just finished&#39;.<br>
   arrayOfFourProcesses do: [:e | Transcript cr; show: e printString].<br>
<br>
   sema wait.<br>
   Transcript cr; cr; show: DateAndTime now asString, &#39; another process just finished&#39;.<br>
   arrayOfFourProcesses do: [:e | Transcript cr; show: e printString].<br>
<br>
   sema wait.<br>
   Transcript cr; cr; show: DateAndTime now asString, &#39; and another process just finished&#39;.<br>
   arrayOfFourProcesses do: [:e | Transcript cr; show: e printString].<br>
<br>
   sema wait.<br>
   Transcript cr; cr; show: DateAndTime now asString, &#39; the last process just finished&#39;.<br>
   arrayOfFourProcesses do: [:e | Transcript cr; show: e printString].<br>
<br>
Dave<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>