From 224769358c4bf5e292298eb63de73eadaefc2c62 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 29 Sep 2011 10:56:13 -0400 Subject: [PATCH] [TimeZone] Fixed race condition with renewing the CurrentTimeZone object. Fixes bug #1055. --- mcs/class/corlib/System/TimeZone.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mcs/class/corlib/System/TimeZone.cs b/mcs/class/corlib/System/TimeZone.cs index 1a682476d5d..cb7caeff3f8 100644 --- a/mcs/class/corlib/System/TimeZone.cs +++ b/mcs/class/corlib/System/TimeZone.cs @@ -55,6 +55,8 @@ namespace System // Fields static TimeZone currentTimeZone; + [NonSerialized] + static object tz_lock = new object (); [NonSerialized] static long timezone_check; @@ -67,13 +69,18 @@ namespace System public static TimeZone CurrentTimeZone { get { long now = DateTime.GetNow (); + TimeZone tz; - if (currentTimeZone == null || (now - timezone_check) > TimeSpan.TicksPerMinute) { - currentTimeZone = new CurrentSystemTimeZone (now); - timezone_check = now; + lock (tz_lock) { + if (currentTimeZone == null || (now - timezone_check) > TimeSpan.TicksPerMinute) { + currentTimeZone = new CurrentSystemTimeZone (now); + timezone_check = now; + } + + tz = currentTimeZone; } - return currentTimeZone; + return tz; } } -- 2.25.1