...not with MemoryBarrier within the synchronized block...
Hm, can you explain this a little more? If one adds a write barrier
after construction of the instance, but before assigning the instance
to the field, as Stoyan's original code did [1], doesn't this have the
desired effect of guaranteeing that the code outside the lock can only
see the fully constructed instance?
Fabian
[1] Copied for reference from Stoyan's posting:
if (provider_ == null)
{
lock (syncLock_)
{
if (provider_ == null)
{
I instance = Activator....
Thread.MemoryBarrier(); // so that any out-of-order writes
complete[1]
provider_ = instance;
}
}
}
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com