It is, but that's a broken implementation of copy-on-write (CoW).
You still need synchronization to comply with the Java memory model.
There's no way to get around that.
The problem we have is this:
+ We have a list of listeners.
+ In order to send out an event to the listeners, we must
traverse the list and call handleEvent(e) on all of them.
+ But we also want to add and remove listeners.
+ We can't add/remove *and* traverse the list simultaneuosly
(ConcurrentModificationException).
+ So we could do this:
synchronized void addListener (Listener l) { ... }
synchronized void removeListener (Listener l) { ... }
synchronized void fireEvent (Event e) { ... }
+ But then we can't have two fireEvent calls running
concurrently. That's bad.
+ So we do this: In fireEvent, synchronize on m_updateLock
long enough to obtain an iterator.
Then, when we are about to mutate the list (add/remove)
lock the m_mutateLock (to prevent concurrent updates,
which is still a no-no). Then lock m_updateLock, and get
an iterator. release m_updateLock.
Copy the list by using the iterator. (The list is
now unlocked and can be used in fireEvent. It is
guaranteed not to change, since we hold m_mutateLock.)
Modify the copy.
synchronize on m_updateLock
Assign the copy to the list member field.
release m_updateLock
Release the m_mutateLock.
Then all writes are guaranteed to be flushed, and
we minimize the time m_updateLock is locked.
/LS
> From: Jonathan Hawkes [mailto:[EMAIL PROTECTED]
>
> http://jakarta.apache.org/commons/collections/apidocs-COLLECTI
> ONS_3_0/org/apache/commons/collections/FastHashMap.html
>
> Isn't this what you mean by copy-on-write? It's broken
> according to the docs.
>
>
> ----- Original Message -----
> From: "Leo Sutic" <[EMAIL PROTECTED]>
> To: "'Avalon Developers List'" <[EMAIL PROTECTED]>
> Sent: Thursday, February 26, 2004 8:45 AM
> Subject: RE: [RT] Notification pattern has interesting effects on IoC
>
>
> > No.
> >
> > Double-checked locking is broken, but copy-on-write isn't.
> >
> > Another way of doing it is to wrap the set of listeners in a
> > read/write lock.
> >
> > /LS
> >
> > > From: Jonathan Hawkes [mailto:[EMAIL PROTECTED]
> >
> >
> >
> ---------------------------------------------------------------------
> > 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]
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]