This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16353] New: static function variable initialization not thread safe
- From: "gianni at mariani dot ws" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Jul 2004 19:06:52 -0000
- Subject: [Bug c++/16353] New: static function variable initialization not thread safe
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I believe that the following piece of code should be thread-safe:
#include <memory>
struct A {};
template <typename T>
T * Singleton()
{
// the following constructor should be called
// exacrlt once but seems unsafe in MT code
static std::auto_ptr<T> l_singleton_ptr( new T );
return &*l_singleton_ptr;
}
Even thought the standard does not specify threading, it does guarentee that
l_singleton_ptr is created exactly once. With GCC 3.4.0, this does not seem to
hold for multi-threaded applications. GCC does support multi-threaded
basic_string and new (to name a few), but guarenteeing the constructor being
called only once for static function variables seems to be a very important and
vary hard (to almost impossible) to work-around.
--
Summary: static function variable initialization not thread safe
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gianni at mariani dot ws
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16353