[squeak-dev] problem with threads

Jordi Delgado jdelgado at lsi.upc.edu
Mon Mar 30 15:03:57 UTC 2009


Hi,

I've been spending some time improving my poor understanding of processes 
in Squeak.

After studying through the usual suspects (essentially the bluebook and 
X.Briffault french book, I've not used yet any VW focused book, to avoid
confusion) and some google-ing, I am trying to find clear examples with
almost-trivial behavior in order to illustrate the main points of squeak
concurrency (I want to teach it, fortunately that will not happen anytime 
soon).

Well, I need to re-define "almost trivial". Let's see. I thought that
the following code (executed from a Workspace):

| s p1 p2 |
s := SharedQueue new: 20.
p1 := [(1 to: 10) do: [:i | s nextPut: i. Processor yield.]] newProcess.
p2 := [(11 to: 20) do: [:i | s nextPut: i. Processor yield.]] newProcess.
p1 priority: Processor activePriority - 1.
p2 priority: Processor activePriority - 1.
p1 resume. p2 resume.
s inspect.

was almost-trivial. It behaves as one would expect: s contains
#(1 11 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10 20)

But, if you agree with me in the "almost-triviality" of the example,
probably you should be able to explain why the following code:

| s p1 p2 |
s := SharedQueue new: 20.
p1 := [1 to: 10 do: [:i | s nextPut: i. Processor yield.]] newProcess.
p2 := [11 to: 20 do: [:i | s nextPut: i. Processor yield.]] newProcess.
p1 priority: Processor activePriority - 1.
p2 priority: Processor activePriority - 1.
p1 resume. p2 resume.
s inspect.

ends up with s containing: 
#(1 11 13 14 15 16 17 18 19 20 nil nil nil nil nil nil nil nil nil nil)

(notice that the only difference is that I am sending a to:do: message
to a SmallInteger, instead of a do: message to an Interval).

So, as of now, I am unable to figure out what is going on.

Any clue? please? I'd rather prefer a sophisticated answer,
otherwise I'm going to feel like an idiot :-))

Thanks a lot in advance,

Bests,

Jordi

PS: This behavior is identical in Squeak 3.9, 3.10 and Pharo, and
in a Linux VM and a Mac VM.




More information about the Squeak-dev mailing list