Bug 29906 - Static method TimeZoneInfo.GetSystemTimeZones() is not thread safe.
Summary: Static method TimeZoneInfo.GetSystemTimeZones() is not thread safe.
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2015-05-09 16:27 UTC by af4178a2
Modified: 2015-11-08 08:16 UTC (History)
3 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description af4178a2 2015-05-09 16:27:07 UTC
If multiple threads are concurrently calling TimeZoneInfo.GetSystemTimeZones() the faster thread initializes the static field "systemTimeZones" and populates the list. A slower thread either immediatelly retrieves an indirect reference to the same list which is still populated by the first thread or instantiates the field and populates the list itself again.

Consider to lock the block which is responsible for initializing the static field "systemTimeZones" until it is completely populated.

The problem still exists in the latest mono/master branch. A short look to the code and you can see the problem immediately.

642			private static List<TimeZoneInfo> systemTimeZones;
643			public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ()
644			{
645				if (systemTimeZones == null) {
646				systemTimeZones = new List<TimeZoneInfo> ();
...				// list is populated
694				}
695				return new ReadOnlyCollection<TimeZoneInfo> (systemTimeZones);
696			}
Comment 1 Marek Safar 2015-05-25 08:57:24 UTC
Fixed in master

Note You need to log in before you can comment on or make changes to this bug.