On Fri, 2002-03-22 at 02:18, Tom Wagner wrote:
> >If I remember correctly, this is what could happen:
> >
> >(1) Thread 1 sees that instance==null.
> >(2) Thread 1 synchronizes on the synchronizer.
> >(3) Thread 1 allocates X bytes of memory for a FileCache.
> >(4) Thread 1 sets instance=(pointer to the allocated memory).
> >(5) Thread 1 calls FileCache() constructor to initialize
> >    the memory area that instance points to -- AFTER it has
> >    already set the instance pointer!
> >(6) Thread 1 unlocks the synchronizer.
> >
> 
> The problem is that you could then have another thread that runs after step
> 4.  It sees that instance is not null and attempts to use it. Ooops, it
> hasn't actually been constructed yet, so the program blows up.

Yes, that's exactly what I wrote below that example.  I skipped the part
about multi-processor systems, though (that even if thread 1 sets the
instance pointer after calling the FileCache() constructor, thread 2
could see the instance pointer being set before the FileCache
initialization due to the lack of synchronization between the
processors), so thanks for clearing that up.




_______________________________________________
Eap-list mailing list
[EMAIL PROTECTED]
http://www.intellij.com/mailman/listinfo/eap-list

Reply via email to