From: Jérémie Laval Date: Fri, 22 Oct 2010 14:15:18 +0000 (+0100) Subject: Use test-and-test-and-set pattern in LazyInitializer::EnsureInitialized X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=adedfedd00fae63a04d3d7e1c03693b7dff6781a;p=mono.git Use test-and-test-and-set pattern in LazyInitializer::EnsureInitialized --- diff --git a/mcs/class/corlib/System.Threading/LazyInitializer.cs b/mcs/class/corlib/System.Threading/LazyInitializer.cs index c63126ee573..9b4ada957ac 100644 --- a/mcs/class/corlib/System.Threading/LazyInitializer.cs +++ b/mcs/class/corlib/System.Threading/LazyInitializer.cs @@ -39,7 +39,8 @@ namespace System.Threading public static T EnsureInitialized (ref T target, Func initFunc) where T : class { - Interlocked.CompareExchange (ref target, initFunc (), null); + if (target == null) + Interlocked.CompareExchange (ref target, initFunc (), null); return target; }