[squeak-dev] Problem with fork

Eliot Miranda eliot.miranda at gmail.com
Wed Jul 1 16:10:38 UTC 2009


Hi Mariano,
    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.

On Wed, Jul 1, 2009 at 7:41 AM, Mariano Martinez Peck <marianopeck at gmail.com
> wrote:

> Hi folks! I am doing some benchmarks and I having problems with fork (I
> think).
>
> I have this method collect:
>
> collect
> |semaphores tr|
> semaphores := Array new: 10.
> tr := ThreadSafeTranscript new.
> tr open.
> 1 to: 10 do: [ :index | semaphores at: index put: Semaphore
> forMutualExclusion ].
>
>     1 to: 10 do: [:i |
>         [
>         tr show: 'one fork'; cr.
>         (semaphores at: i) signal.
>         ] fork
>     ].
>
>     semaphores do: [:each | each wait ].
>     tr show: 'all forks proccesed'; cr.
>
>
> 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.
>
> I would expect something like this:
>
> one fork
> one fork
> one fork
> one fork
> one fork
> one fork
> one fork
> one fork
> one fork
> one fork
> all forks proccesed
>
> But the output is:
>
>
> all forks proccesed
> one fork
> one fork
> one fork
> one forkone fork
> one fork
> one fork
> one forkone fork
> one fork
> one fork
> one forkone fork
>
> So, I guess it isn't working :(   I don't know too much about forks so any
> help is welcome!
>
> can be a problem with  ThreadSafeTranscript  ? If so, how could I test if
> my code is working as expected ?
>
> Thanks,
>
> Mariano
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090701/ac5f8bac/attachment.htm


More information about the Squeak-dev mailing list