[Mono-list] CurrentTimeZone race condition - fix

Jaroslaw Kowalski jarek@merkury.atm.lan
Sun, 18 Aug 2002 11:45:41 +0200


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--176226307-948594509-1029663941=:23901
Content-Type: TEXT/PLAIN; charset=US-ASCII


Hi all!

Included is a patch that eliminates a race condition that occurs in
CurrentTimeZone.GetDaylightChanges() (in TimeZone.cs).

Before the patch, when 2 threads call DateTime.Now at the same time (for
the very first time in the whole program) an exception is thrown, when a
duplicate key is being added to the hashtable.

in <0x002ff> 00 System.Collections.Hashtable:PutImpl (object,object,bool)
in <0x00018> 00 System.Collections.Hashtable:Add (object,object)
in <0x00279> 00 System.CurrentTimeZone:GetDaylightChanges (int)
in <0x00028> 00 System.TimeZone:IsDaylightSavingTime (System.DateTime)
in <0x0002b> 00 System.CurrentTimeZone:GetUtcOffset (System.DateTime)
in <0x0008f> 00 System.DateTime:.ctor (bool,long)
in <0x00036> 00 System.DateTime:get_Now ()

The patch that adds a critical section in  GetDaylightChanges() which
fixes the problem. Can you, please add it to CVS?

Jarek

--176226307-948594509-1029663941=:23901
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="timezone.patch"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.SGI.4.44.0208181145410.23901@merkury.atm.lan>
Content-Description: 
Content-Disposition: attachment; filename="timezone.patch"

SW5kZXg6IFRpbWVab25lLmNzDQo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09DQpS
Q1MgZmlsZTogL21vbm8vbWNzL2NsYXNzL2NvcmxpYi9TeXN0ZW0vVGltZVpv
bmUuY3Msdg0KcmV0cmlldmluZyByZXZpc2lvbiAxLjgNCmRpZmYgLXUgLXIx
LjggVGltZVpvbmUuY3MNCi0tLSBUaW1lWm9uZS5jcwk5IEp1biAyMDAyIDA1
OjU0OjI0IC0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