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

James Foster james at foster.net
Thu Apr 29 14:45:17 UTC 1999


An out-of-bounds error sounds like you are iterating over a collection that
is being modified (perhaps, as you suggest, by GC activity). Rather than get
involved with semaphores, I'd suggest iterating over copies of collections.
For example, modify PostOffice>>#incoming:from: to send #keysAndValuesDo: to
a copy of <subscribers>.

But then I've only given this a couple minutes thought, and I don't have a
Squeak image up to try your code, so take this for what it is worth!

James Foster

-----Original Message-----
From: Peter Smet <peter.smet at flinders.edu.au>
To: squeak at cs.uiuc.edu <squeak at cs.uiuc.edu>
Date: Thursday, April 29, 1999 12:46 AM
Subject: Publish-Subscribe, Weak Arrays and Garbage Collection...


>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
>
>
>
>
>
>





More information about the Squeak-dev mailing list