Is Set growth thread-safe?

Ross Boylan RossBoylan at stanfordalumni.org
Thu Sep 22 18:43:21 UTC 2005


Thanks everyone for setting me straight.  It seems reasonable that
classes are not generally thread-safe, but in the original issue that
got me into this, WeakIdentityKeyDictionary, it seems problematic.

WeakIdentityKeyDictionaries hold the system dependency information in
Object's class variables DependentsFields and EventsFields.  It is at
least possible for a single application to serialize its use of the
corresponding messages, but 2 separate applications in the same image
have no way to do so.  Even within a single application serializing
access is challenging, given that read access must block while write
access is happening.

Using the Model or EventsModel class clearly reduces the chances of
problems, but the individual entries they employ are
IdentityDictionaries and they may have similar issues (granted that
the problem of multiple application coordination is now gone).

These issues might explain some erratic failures I've seen in my
application.  It has a background thread that does an update that
triggers dependencies.  So if the user is doing something interactively
at the same time, bad stuff can happen.  I tried to put appropriate
guards in my code, but didn't realize the update mechanism itself
needed protection.

In short, it seems too easy to shoot yourself in the foot with the
present system design, unless the fact that threads are not pre-emptive
provides some extra safety that I'm missing.  By the usual logic of
providing thread-safety around classes as needed, wouldn't it be
better for Object, Model, and EventModel to protect the update
mechanisms appropriately?

Ross Boylan




More information about the Squeak-dev mailing list