Publish-Subscribe, Weak Arrays and Garbage Collection...

Peter Smet peter.smet at flinders.edu.au
Thu Apr 29 05:42:26 UTC 1999


Hi all,

I have been trying to implement a publish subscribe mechanism along
the lines of Dolphin and VW. With it, any object can trigger events such as

Transcript trigger: #bang.
an interest in events is registered by the message:
Transcript when: #bang send: #run to: self
etc.

The disadvantage of publish subscribe is that you must explicitly deregister
objects from the mechanism for them to be garbage collected.
I have tried to get around this by using  weakKeyDictionaries to hold both
the publishers and the subscribers. If there are no remaining references to
either the publisher or the subscriber, these will be garbage collected, and
no events will be passed to these deceased objects. This certainly makes
everything a lot easier to maintain.

Everything seems to be working as planned. However, if I run some processes
where lots of temporary objects are created and many messages passed,
sooner or later some kind of synchronization problems occur. The normal
pattern
is that a WeakKeyDictionary attempts to access an array at an out of bounds
index. I suspect that the finalization process is "stealing" my weakDict
keys when
objects are garbage collected. This error can be created by running
PostOffice start. PostOffice stop will halt the thread.
PostOffice initialize clears the dictionaries with publishers/subscribers.

So my questions are:
Is this a synchronization problem with the FinalizationProcess in WeakArray?
is the WeakKeyDictionary class process safe, or how can I make it so?
Do I need to integrate my (PostOffice) class with the FinalizationSemaphore
or FinalizationLock of class WeakArray - how would I do this, how do I
access
these semaphores?

A change set is attached. Some of the code is in Object, and Message,
under "publish-subscribe"

Using 2.4b under win NT SP3. Any insights greatly appreciated.

Peter






Content-Type: application/octet-stream;
	name="Publish-Subscribe.29Apr244pm.cs"
Content-Disposition: attachment;
	filename="Publish-Subscribe.29Apr244pm.cs"

Attachment converted: Anon:Publish-Subscribe.29Apr244pm.cs 
(????/----) (000098AD) 





More information about the Squeak-dev mailing list