general morphic concurrency question

emerson at cs.pdx.edu emerson at cs.pdx.edu
Tue Dec 14 00:53:44 UTC 2004


Howdy!

I've got a general question about concurrency in squeak.  It will be easier for
me to explain the question if I can explain how I arrived at it - so please
bear with me!

I've been trying to do some graphing of streaming data using PlotMorph, to add a
series of points to a graph as the point data is coming in.  Here's a simplified
snippet, where the forked block represents the stream drawing to the PlotMorph
every so often:

plotMorph := PlotMorph new.
plotMorph openInWorld.

[
0 to: 1000 do: [ :index |
	plotMorph series: #a addPoint: index@(index cos).
	(Delay forMilliseconds: 10) wait.
]
] fork.

At some point during execution, an instance variable (a Form) of the plotMorph
will be set to nil and a message will be sent to it.  Bad news!  I've tracked
the problem to two threads:

(1) One thread is the WorldState, trying to update all damaged Morphs.  When it
gets to plotMorph, it calls PlotMorph>>form, which starts by lazily
initializing  the Form and then doing some housekeeping...

(2) Meanwhile (sort of), my thread in the code above adds another point to
plotMorph, and signals the PlotMorph>>changed method, which sets form to nil.

By the time thread 1 has exits the PlotMorph>>form method, form had been reset
to nil by thread 2.  Oops!


A solution to the problem would be to disallow the adding of points (or more
generally, calls to Morph>>changed) until the WorldState is finished drawing. 
This seems like a more general problem, one that has probably been solved
elsewhere.  Is it, and has it?  Could someone fill me in?

Thanks,

Emerson



More information about the Squeak-dev mailing list