commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "christopher marshall" <oxbow_la...@hotmail.com>
Subject Are FastArrayList/FastHashMap broken (unthreadsafe)
Date Fri, 17 May 2002 10:38:09 GMT
I have just been looking through the source code to the classes 
org.apache.commons.collections.FastHashMap and 
org.apache.commons.collections.FastArrayList - these classes seem totally 
broken to me because they are designed for use within a multi-threaded 
environment but are not threadsafe within the definition of the Java memory 
model.

I accept that presumably these classes have been pored over by minds 
superior to my own, but here is my reasoning:

Firstly, the internal "fast" boolean is not volatile, hence 2 separate 
Threads may be of a different opinion as to whether the Map/List is running 
in fast mode or not (If a primitive variable is non-volatile, the JVM is 
entirely free to read the value from Thread-local memory).

Secondly, even if 2 threads agree that the Map/List is running in fast mode, 
the Java memory model doesn't guarantee that non-synchronized changes will 
be visible across multiple Threads (because synchronization acts as a 
"main-memory barrier"). Since access to the Map/List via the get() method is 
not synchronized in fast mode, but will be to the put()/add() methods, it 
isn't clear that a Thread performing just reads will see changes an 
arbitrary amount of time after they have actually happened.

The version I have is Commons-Collections 2.0.

Thanks,

P.S. Apologies if this is directed at the wrong mailing list - this is my 
first contribution.

Chris Marshall

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message