http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_0/org/apache/commons/collections/FastHashMap.html

http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

The memory model is pretty screwy up to (and including) java 1.4.  I believe
that the have fixed some of the issues in 1.5.  The problem is that your
operations don't "have to" be done in order.  They just have to "appear" to
be done in the correct order according to the executing thread.  Thus
"m_Listeners" could be assigned a reference to "clone" before the clone was
fully initialized.  Another thread could then get a hold of an invalid
"m_Listeners".



----- Original Message ----- 
From: "Niclas Hedhman" <[EMAIL PROTECTED]>
To: "Avalon Developers List" <[EMAIL PROTECTED]>
Sent: Thursday, February 26, 2004 9:11 AM
Subject: Re: [RT] Notification pattern has interesting effects on IoC


> On Thursday 26 February 2004 23:36, Jonathan Hawkes wrote:
> > Isn't copy-on-write broken along with double-checked locking (under the
> > 1.4- memory model)?
>
> I would be happy to see any references on this.
>
> My typical code looks;
>
> public void addMyListener( MyListener listener )
> {
>     synchronized( m_Listeners )
>     {
>         ArrayList clone = (ArrayList) m_Listeners.clone();
>         clone.add( listener );
>         m_Listeners = clone;
>     }
> }
>
> public void removeMyListener( MyListener listener )
> {
>     synchronized( m_Listeners )
>     {
>         ArrayList clone = (ArrayList) m_Listeners.clone();
>         clone.remove( listener );
>         m_Listeners = clone;
>     }
> }
>
> And I can't figure out how this could be faulty, even on exotic hardware.
>
>
> Niclas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to