This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug libstdc++/12658] Thread safety problems in locale::global() and locale::locale()


------- Additional Comments From peturr02 at ru dot is  2004-07-28 17:40 -------
The problem in locale::locale() is still present:

  __glibcxx_mutex_define_initialized(locale_cons_mutex);
  __glibcxx_mutex_define_initialized(locale_global_mutex);
} // namespace __gnu_internal

namespace std 
{
  using namespace __gnu_internal;

  locale::locale() throw() : _M_impl(0)
  { 
    _S_initialize();
    __gnu_cxx::lock sentry(__gnu_internal::locale_cons_mutex);
    _S_global->_M_add_reference();
    _M_impl = _S_global;
  }

  locale
  locale::global(const locale& __other)
  {
    _S_initialize();
    _Impl* __old;
    {
      __gnu_cxx::lock sentry(__gnu_internal::locale_global_mutex);
      __old = _S_global;
      __other._M_impl->_M_add_reference();
      _S_global = __other._M_impl;

Note that while locale::locale() and locale::global() both lock a mutex
before touching _S_global, they lock different mutexes. There is thus nothing
to stop one thread from executing locale::global() while another executes
locale::locale(). As already noted, this can (and does) lead to serious
problems.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12658


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