> On Friday 27 February 2004 00:20, Leo Sutic wrote:
> > But don't you have to synchronize on a lock for m_Listeners when
> > you traverse the list for sending notifications?
>
> > Otherwise you can get:
> >
> > public void addMyListener( MyListener listener )
> > {
> > synchronized( m_Listeners )
> > {
> > ArrayList clone = (ArrayList) m_Listeners.clone();
> > m_Listeners = clone;
> > clone.add( listener );
> > }
> > }
>
> Hmmm...
>
> public void addMyListener( MyListener listener )
> {
> ArrayList clone;
> synchronized( m_Listeners )
> {
> clone = (ArrayList) m_Listeners.clone();
> clone.add( listener );
> }
> m_Listeners = clone;
> }
>
> ??
That won't work either. You just can't beat the flawed memory model. The
following is a terrific resource.
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
Doug Lea proposes many work-arounds and then shoots most of them down :)
I think that the memory model was actually modified for java 1.5.
Jonathan Hawkes
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]