Skip to content

Commit f330930

Browse files
jstedfastp12tic
authored andcommitted
[TimeZone] Fixed race condition with renewing the CurrentTimeZone object.
Fixes bug #1055.
1 parent 20d8e01 commit f330930

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

mcs/class/corlib/System/TimeZone.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public abstract class TimeZone
5656
// Fields
5757
static TimeZone currentTimeZone;
5858

59+
[NonSerialized]
60+
static object tz_lock = new object ();
5961
[NonSerialized]
6062
static long timezone_check;
6163

@@ -68,13 +70,18 @@ protected TimeZone ()
6870
public static TimeZone CurrentTimeZone {
6971
get {
7072
long now = DateTime.GetNow ();
73+
TimeZone tz;
7174

72-
if (currentTimeZone == null || (now - timezone_check) > TimeSpan.TicksPerMinute) {
73-
currentTimeZone = new CurrentSystemTimeZone (now);
74-
timezone_check = now;
75+
lock (tz_lock) {
76+
if (currentTimeZone == null || (now - timezone_check) > TimeSpan.TicksPerMinute) {
77+
currentTimeZone = new CurrentSystemTimeZone (now);
78+
timezone_check = now;
79+
}
80+
81+
tz = currentTimeZone;
7582
}
7683

77-
return currentTimeZone;
84+
return tz;
7885
}
7986
}
8087

0 commit comments

Comments
 (0)