The non-thread-safe part of Format is where it accesses the various
global locale settings. The thread-safe version take a TFormatSettings
record that provides a local copy of all the relevant settings, so it no
longer needs to access the shared global values. If, when you create an
exception object, your format string doesn't require access to any of
those global variables, then it is safe to create that object.

Safe format strings include s, d, u, x, and p, as long as the data value
is not a Variant. If the data value is a Variant, then there may be a
call to FloatToStr via FormatVarToStr and Variants._VarToLStr.

The e, f, g, m, and n format strings trigger access to the
DecimalSeparator, ThousandSeparator, CurrencyString, CurrencyFormat, and
NegCurFormat variables. In addition, the m format string requires
accessing the CurrencyDecimals variable.

Furthermore, accessing those variables is only unsafe if their values
can ever change while a call to Format is active. In the VCL source
code, they only change due to calls to GetLocaleFormatSettings and
GetFormatSettings. Delphi never calls the former, and it only calls the
latter in two places. The first is in the initialization section of
SysUtils.pas, which is required for initializing the variables when your
program starts up. The other place is in TApplication.CheckIniChange,
and the function is only called if Application.UpdateFormatSettings is
True. It's True by default, but you can set it to False. CheckIniChange
gets called in response to your main window receiving a wm_WinIniChange
or TaskbarCreated message.

--
Rob

Wow, that is very detailed answer! Now everything seems much clearer to me.

So basically, there are possible races in Exception Fmt constructors. But the reason why nobody have complained about raising exception causes thread races is that the only time a race may occur is when an exception object is created using Fmt constructors right in the middle of another thread / process changes program / system format settings.

Once in ten thousand years? Well, that sounds good enough for me! :D

Thanks very much, Rob!

_________________________________________________________________
与联机的朋友进行交流,请使用 Live Messenger; http://get.live.com/messenger/overview
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to