This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/12855] Thread safety problems in ios_base::Init
- From: "peturr02 at ru dot is" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 Oct 2003 09:48:31 -0000
- Subject: [Bug libstdc++/12855] Thread safety problems in ios_base::Init
- References: <20031031094301.12855.peturr02@ru.is>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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.