C++ io, thread safety, and setlocale
Loren James Rittle
rittle@latour.rsch.comm.mot.com
Mon Apr 21 23:06:00 GMT 2003
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
More information about the Libstdc++
mailing list