[Mono-devel-list] [PATCH] Reworked unified Locale classes

Ben Maurer bmaurer at ximian.com
Thu Jun 16 10:24:19 EDT 2005

On Thu, 2005-06-16 at 11:52 +0200, Kornél Pál wrote:
> Hi,
> >> Try using [ThreadStatic], it's a bit cleaner.
> >
> > It examined the documentation and it's really cleaner and may be faster as
> > well.
> In fact a global lock can be used as well because ResourceManager is thread
> safe and locks itself so this will not degrade performance. In this case no
> thread static variable is necessary a simple static variable can be used.
> I attached a diff file with a Locale.cs that uses static variable and lock.
> If you have time and gears please benchmark all of these different ways
> (LocalDataStoreSlot, [ThreadStatic], lock)

Benchmarks really don't matter here I think. The *only* reason people
would use the Locale class is when an exception gets thrown and we need
to get the error message. Since an exception is 1) exceptional and 2)
already slow, not too much harm in slowing it down more :-).

So, we should go for the simplest design. I think the simplest one was
the one using ThreadStatic.

bool inside_gettext


if (inside_gettext)
    // don't do anything
    return msg;

try {
    inside_gettext = true;
    return ...
} catch {
    inside_gettext = false;

-- Ben

More information about the Mono-devel-list mailing list