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

Miguel de Icaza miguel@ximian.com
28 Oct 2001 07:40:14 -0500

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.