Hi Mariano,<div><br></div><div> Smalltalk's scheduler is preemptive across priorities and co-operative within priorities, which is a well-chosen real-time scheduling policy giving precise control over processes. Because all your processes have the same priority they don't preempt the first process and so they don't get to run until after the doit has executed and the system has returned to some idle loop state. If instead you change your code to either use a higher priority, e.g. [...] forkAt: Processor activePriority + 1, or to use yield, e.g. [....] fork. Processor yield, then you'll be able to get your desired behaviour. <br>
<br><div class="gmail_quote">On Wed, Jul 1, 2009 at 7:41 AM, Mariano Martinez Peck <span dir="ltr"><<a href="mailto:marianopeck@gmail.com">marianopeck@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi folks! I am doing some benchmarks and I having problems with fork (I think).<br><br>I have this method collect:<br><br>collect<br>|semaphores tr|<br>semaphores := Array new: 10.<br>tr := ThreadSafeTranscript new.<br>tr open.<br>
1 to: 10 do: [ :index | semaphores at: index put: Semaphore forMutualExclusion ].<br><br> 1 to: 10 do: [:i |<br> [<br> tr show: 'one fork'; cr.<br> (semaphores at: i) signal.<br> ] fork <br>
].<br><br> semaphores do: [:each | each wait ].<br> tr show: 'all forks proccesed'; cr.<br> <br><br>What I want is that the method collect returns when ALL of the forks created inside, are finished. Obviously in my real code, I don't do a transcript show: but another thing. <br>
<br>I would expect something like this:<br><br>
one fork<br>one fork<br>
one fork<br>
one fork<br>
one fork<br>one fork<br>
one fork<br>
one fork<br>
one fork<br>one fork<br>all forks proccesed<br><br>But the output is:<br><br><br>all forks proccesed<br>one fork<br>one fork<br>one fork<br>one forkone fork<br>one fork<br>one fork<br>one forkone fork<br>one fork<br>one fork<br>
one forkone fork<br><br>So, I guess it isn't working :( I don't know too much about forks so any help is welcome!<br><br>can be a problem with ThreadSafeTranscript ? If so, how could I test if my code is working as expected ?<br>
<br>Thanks,<br><font color="#888888"><br>Mariano<br><br>
</font><br><br>
<br></blockquote></div><br></div>