I had this type of discussion when I first joined these lists, it was regarding the use of the volatile keyword with Ole. I hope this summary helps to shed some light on the problem.
The double checking issue has two problems, the one relevant to this discussion is the behaviour of processor caches on a MP machine using a weak memory model. On these platforms the original code is slightly worse than just using the volatile keyword instead of the synchronization. The reason for this is that the contents of the original reference are not guaranteed to be the same on each processor (it is with the volatile keyword) and neither are the contents of the object being referenced (the same in both cases). The synchronised keyword is forcing the current processor to flush its cache to main memory before and after executing the code in the synchronisation block. This means that the current processor will be using a copy the main memory image. In a weak memory model the other processors may not have flushed their caches and may actually have different values in their cache. These images may (or may not) be consistent depending on how synchronization is used and the sequence of reads. A possible scenario may be, for example Processor 1 Processor 2 - synchonrize and flush to memory - create new object (object 1) - assign reference - finish synchronize and flush to memory - read reference (points to object 1) - synchonrize and flush to memory - create new object (object 2) - assign reference - finish synchronize and flush to memory - access reference already obtained (points to object 1) - read object referenced (object 1) At this point processor 2 has read memory that is inconsistent with processor 1 (the reference has changed) and may even be invalid if the memory used by object 1 has been reused. The only safe way is to use synchronization on all access to the object so that the latest version is obtained from main memory and updates are prevented. The only safe use of the volatile keyword is for primitives or for references to thread safe objects. HTH, Kev Kevin Conner This is a personal e-mail. Any views or opinions presented are solely those of the author and do not necessarily represent those of Orchard Information Systems Ltd. ------------------------------------------------------- This SF.NET email is sponsored by: FREE SSL Guide from Thawte are you planning your Web Server Security? Click here to get a FREE Thawte SSL guide and find the answers to all your SSL security issues. http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development