logo       

Re: BlockClosure>>fork problem: msg#00094

lang.smalltalk.squeak.beginners

Subject: Re: BlockClosure>>fork problem

George,

You'll find that writing to the Transcript always slows things down. I
assume it's the time for writing to the Transcript that also causes
the second process to start after a different interval each time.
Writing the results into an OrderedCollection will be much faster, and
more predictable:

a := OrderedCollection new.
[10 timesRepeat: [a addLast: '2'. (Delay forMilliseconds: 1) wait]] fork.
[10 timesRepeat: [a addLast: '1'. (Delay forMilliseconds: 1) wait]] fork.
a inspect.

consistently gives 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1.

Without the delay:

a := OrderedCollection new.
[10 timesRepeat: [a addLast: '2']] fork.
[10 timesRepeat: [a addLast: '1']] fork.
a inspect.

consistently gives 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1.

Cheers,
Michael


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise