[Newbies] BlockClosure>>fork problem

Michael Davies mykdavies+squeak at gmail.com
Tue Feb 20 10:05:53 UTC 2007


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


More information about the Beginners mailing list