Fwd: native threads

Tim Rowledge tim at sumeru.stanford.edu
Sun Apr 17 21:11:13 UTC 2005


Ned Konz <ned at squeakland.org> wrote:

> On Sunday 17 April 2005 10:50 am, Ramiro Diaz Trepat wrote:
> > But why did that guy have to write those Processor yields in that code
> > snippet to get it filled unsequentially (not '11111...22222222' ) on
> > two equal processes forked trying to insert the numbers in the same
> > shared queue ?
> 
> Because that's the way that Squeak processes work.
> 
> Just because his expectation of how the processes *should* fill the queue did 
> not match the way they *did* fill the queue does not mean that there's a bug.
Editors note: To protect my reputation for the future I should point out that I was 'that guy' adding the Processor yield in order to try to illustrate the scheduling model of squeak to Ramiro; and so all following 'him' 'he' etc should be read as 'Ramiro'.
[snip]

> 
> As has been noted before, if he were to do this prior to running his two 
> forked processes to fill the queue, he'd have the expected behavior (assuming 
> that the queue-filling processes were started at a priority below Processor 
> userInterruptPriority). (Warning: untested code!)
> 
> [ | d | d := Delay forMilliseconds: 1.
>  [ d wait ] repeat ] forkAt: Processor userInterruptPriority.
And even here there are some little tricky bits:-
a) if the entire code fragments took less thant 1mS to run, then there would be no visible effect in the resultant  list of 1111111222222.
b) since each loop of writing to the list would likely take much less than 1mS each, the output is likely to be '1111122222111111222222111111' etc. Note that this is nothing whatsoever to do with Squeak per se. Any multitasking model that timeslices would have the same kind of result UNLESS you deliberately yield in each loop or otherwise have some throttling, access guarding or whatever. It's hard to imagine a scheduler model that would work out to switch between each iteration in a set of loops. Just for starters, how often will the tasks be simple loops and not complex procedures?

Could any _really_ imagine that the original code snippet would produce '12121212121212121'?



tim
--
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
Useful random insult:- Several nuts over fruitcake minimum.



More information about the Squeak-dev mailing list