From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexandre Oliva To: Nathan Myers Cc: egcs@cygnus.com Subject: Re: How EGCS with multi-threaded compliance? Date: Fri, 10 Apr 1998 21:44:00 -0000 Message-id: References: <004501bd5f56$50b61ba0$2c91b780.cygnus.egcs@pitcheri.gsfc.nasa.gov> <352ECFB1.1E5F8442@cygnus.com> X-SW-Source: 1998-04/msg00466.html Nathan Myers writes: > Dirk Broer wrote: >> I'm searching for a C++ compiler that is multi-thread compliance. > Aren't we all... An area most compilers haven't got right yet is > void f() > { > static A a; > } > The constructor for 'a' is supposed to run the first time you enter f(). Actually, it is supposed to run the first time control passes through the declaration-statement, unless the object is initialized together with namespace-scope objects. Since there's no requirement in the standard about making this thread-safe, and, in fact, the C++ Standard does not talk about thread-safety at all, I don't think compilers should care about this, since it *is* possible to perform a similiar initialization in a thread-safe manner: static Mutex init_lock; inline A& f_initialize_a() { static A *a = 0; if (!a) { Lock lock(init_lock); // released when lock goes out of scope if (!a) a = new A(); } return *a; } void f() { A& a = f_initialize_a(); } Of course, a compiler might generate this code implicitly, but I don't think I would appreaciate that much hidden overhead. -- Alexandre Oliva mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org http://www.dcc.unicamp.br/~oliva Universidade Estadual de Campinas, SP, Brasil