title: Is ostream operator<< in libstdc++ thread-hostile?
body: <p><code>ostream</code> operator<code>&lt;&lt;</code> uses <code>num_put::put()</code> 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 <code>num_put::put()</code> calls <code>num_put::do_put()</code>, which calls<br>
  <code>num_put::_M_insert_float()</code>, which <code>calls __convert_from_v()</code>:</p>
  
  <pre><code>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
  </code></pre>
  
  <p><code>__convert_from_v()</code> checks the current global locale, and if it's different from "C" then it calls <code>setlocale()</code> to set the global locale to "C", then uses <code>vsnprintf()</code> to format the number, then calls <code>setlocale()</code> again to revert to the old locale.</p>
  
  <p>Since <code>setlocale()</code> affects all threads, it would seem that calling <code>ostream</code> operator<code>&lt;&lt;</code> 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!</p>