ostream
operator<<
uses num_put::put()
for number formatting. I'm trying to follow the code. I'll link to OSX files but similar files appear on some other systems I looked at. It seems to me that num_put::put()
calls num_put::do_put()
, which calls
num_put::_M_insert_float()
, which calls __convert_from_v()
:
http://www.opensource.apple.com/source/libstdcxx/libstdcxx-60/include/c++/4.2.1/bits/c++locale.h
http://www.opensource.apple.com/source/libstdcxx/libstdcxx-60/include/c++/4.2.1/bits/locale_facets.tcc
http://www.opensource.apple.com/source/libstdcxx/libstdcxx-60/include/c++/4.2.1/bits/locale_facets.h
__convert_from_v()
checks the current global locale, and if it's different from "C" then it calls setlocale()
to set the global locale to "C", then uses vsnprintf()
to format the number, then calls setlocale()
again to revert to the old locale.
Since setlocale()
affects all threads, it would seem that calling ostream
operator<<
with a floating point number is unsafe in a multi-threaded application which has the global locale set to something else than "C". But that would be very strange, so what am I missing? Thanks!