This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ io, thread safety, and setlocale


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]