This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: C++ io, thread safety, and setlocale
- From: Loren James Rittle <rittle at latour dot rsch dot comm dot mot dot com>
- To: libstdc++ at gcc dot gnu dot org
- Cc: rutt at chezrutt dot com
- Date: Mon, 21 Apr 2003 18:05:58 -0500 (CDT)
- Subject: Re: C++ io, thread safety, and setlocale
- Organization: Networks and Infrastructure Lab (IL02/2240), Motorola Labs
Hi,
> Pehaps this is a FAQ, but I couldn't find anything.
You could find more details about this in section 5.6 of
libstdc++-v3/docs/html/faq/index.html . Note well the exact words
where we weasel out in various cases; mainly involving unknown libc
implementation. One could conceive of a thread implementation where
setlocale acted on a per-thread basis but I'd agree in my experience
this is unlikely.
> How can this be thread safe without some locking of some sort?
Even if that particular call (or pair of calls to set and then reset)
was wrapped with a lock, it doesn't really improve the situation since
your user-level code may have called setlocale directly or other IO
calls that indirectly use the global locale settings. At the moment,
the C++ library code base is favoring locale support over thread
support in the generic IO/locale code. I believe that for people
using the "C" locale, we should try harder to be thread-safe in all IO
cases (by skipping the setlocale call); however with the unconditional
calls to setlocale; we can't be at the moment.
Sorry,
Loren