[squeak-dev] Problem with fork

Mariano Martinez Peck marianopeck at gmail.com
Wed Jul 1 17:29:08 UTC 2009


On Wed, Jul 1, 2009 at 4:22 PM, Igor Stasenko <siguctua at gmail.com> wrote:

> 2009/7/1 Mariano Martinez Peck <marianopeck at gmail.com>:
> > 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 ?
> >
>
> Mariano, sorry it way my mistake. In example that i gave you on IRC ,
> i put Semaphore forMutualExclusion,
> while obviously it should be simply: Semaphore new.
>

Sorry, I was having lunch.

Igor: I didn't know that sig__ where you :)   Actually, I was just doing
some tests and saw that using Semaphore new instead of Semaphore
forMutualExclusion  do what I wanted. I then saw forMutualExclusion
implementation and it does a signal after the new :)

Thanks for the help!!


>
>
>
> > Thanks,
> >
> > Mariano
> >
> >
> >
> >
> >
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090701/0f7fa96a/attachment.htm


More information about the Squeak-dev mailing list