[Mono-list] Class library developers: locking issues to keep in mind

Alexander Klyubin klyubin@aqris.com
Sun, 28 Oct 2001 21:43:22 +0000


Hm... As far as I remember how volatile works in Java, even making 
reference volatile does not save you from the situation when the 
reference is OK, but the object it points to has not been completely 
initialized from point of view of a thread where some code accesses the 
object using this reference... But I'm not 100% sure on this.

Regards,
Alexander Klyubin

Miguel de Icaza wrote:

> On Sun, 2001-10-28 at 05:20, Alexander Klyubin wrote:
> 
>>I don't know that much about .NET memory model as of Java's one, but in 
>>Java the code with on-demand locking you provided is called 
>>Double-checked Locking (DCL). The problem with it is that it is not 
>>guaranteed to work in all JVMs as synchronizing memory thread's own 
>>local memory with shared main memory accessible to all threads can work 
>>differently in different JVMs. Maybe memory model is organized 
>>differently in .NET languages compared to Java. But as similarity 
>>between C# and Java is realy big, I suspect memory model should be quite 
>>similar if not the same.
>>
> 
> This is a good point.
> 
> The problem comes not from the language, but from modern computer
> architectures in SMP scenarios (the second link in your post goes into
> detail about this)
> 
> Sadly none of the articles offers a good solution to the problem. Maybe
> we need to discuss with the .NET people the semantics of lock in C# (we
> could have explicit read/write barriers generated) or use volatiles.
> 
> Miguel.
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>