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++/12855] Thread safety problems in ios_base::Init


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From peturr02 at ru dot is  2003-10-31 09:48 -------
(I somehow hit commit before it was ready)

ios_base::Init is not threadsafe:

ios_base::Init::Init()
{
  if (_S_ios_base_init == 0)
    {
      // Lots of stuff that initializes cin, cout etc.

      _S_ios_base_init = 1;
    }
  ++_S_ios_base_init;
}

ios_base::Init::~Init()
{
  if (--_S_ios_base_init == 1)
    {
       // Flush cout, cerr etc.
    }
}

If two threads run Init::Init() or Init::~Init() at the same time, both will
access the standard streams, which are not threadsafe themselves. Also,
_S_ios_base_init is not updated atomically, so it may be corrupted.


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