commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Berin Loritsch" <>
Subject RE: [Collections] StaticBucketMap not thread safe
Date Tue, 25 Jun 2002 20:22:35 GMT
> From: Jack, Paul [] 
> Ugh.  StaticBucketMap has double-checked-locking-esque problems.
> Since access to the node array (m_buckets) isn't 
> synchronized, different processors can disagree as to whether 
> an element in that array is null or not.
> Worse, the reference to a Node placed in that array can be 
> written before the Node is fully constructed, because 
> compilers/ pipelines can feel free to reorder those 
> instructions.  Almost every operation on a StaticBucketMap 
> can therefore fail in unexpected ways.
> Only way to fix it is to synchronize every access to 
> m_buckets. I'm not sure how badly that will affect 
> performance but it definitely wouldn't be as optimized.

What about making the m_buckets volatile?  Wouldn't that

I can tell you this much--if you have to synchronize on
every access to m_buckets then you lose all advantage of
BucketMap and you would actually be better off working
with a synchronized map via Collections.synchronizedMap().

What will end up happening is essentially the same as
every access will be synchronized at the same point.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message