[Bug libstdc++/12855] Thread safety problems in ios_base::Init
peturr02 at ru dot is
gcc-bugzilla@gcc.gnu.org
Fri Oct 31 09:54:00 GMT 2003
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.
More information about the Gcc-bugs
mailing list