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

Miguel de Icaza miguel@ximian.com
29 Oct 2001 11:56:21 -0500

On Sun, 2001-10-28 at 16:43, Alexander Klyubin wrote:
> 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.

I think we are now talking about wildly different things here :-)

The problem was the double check, and the fact that a thread in a
different CPU might have assigned a value to the variable on a separate
thread, but the change is living in the other cpu's cache.

All of this is happening inside a *lock* statement.

So conceptually:

	lock (typeof (this)){
		if (val != 0)
		val = 1;

The problem still exists there with integers.