public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jason at redhat dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/13684] local static object variable constructed once but ctors and dtors called multiple times on same memory when called in multiple threads
Date: Sat, 04 Sep 2004 18:06:00 -0000	[thread overview]
Message-ID: <20040904180647.14335.qmail@sourceware.org> (raw)
In-Reply-To: <20040114172507.13684.evijaykumar@yahoo.com>


------- Additional Comments From jason at redhat dot com  2004-09-04 18:06 -------
Subject: Re:  local static object variable constructed once
 but ctors and dtors called multiple times on same memory when called in
 multiple threads

On 31 Aug 2004 06:41:13 -0000, "adah at netstd dot com" <gcc-bugzilla@gcc.gnu.org> wrote:

> It looks to me that the solution applies the Double-Checked Locking Pattern, 
> and could be unsafe on some multi-processor platforms, most notably Alpha and 
> IA-64.

Hmm, indeed.  As I understand it from some googling, particularly this thread:

  http://www.google.com/groups?threadm=6kuldj$4sk%40bmtlh10.bnr.ca

the problem is that modern architectures such as the ones you mention can
reorder stores and loads so that another processor could see the guard
variable set, but the controlled variable not yet fully initialized.  The
cheapest workaround is to add memory barriers in the initialization path if
the architecture reorders stores (SPARC also does this) and in the
already-initialized path if it reorders loads.

Unfortunately, pthreads (for instance) don't have a portable way of forcing
a memory barrier other than with a mutex.

I suppose the simplest fix is just to remove the check in the
compiler-generated code, but having all calls to functions with initialized
static locals go through the same mutex seems rather unfortunate.  Hmm.

Jason


-- 


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


  parent reply	other threads:[~2004-09-04 18:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-14 17:25 [Bug c++/13684] New: " evijaykumar at yahoo dot com
2004-01-14 17:27 ` [Bug c++/13684] " evijaykumar at yahoo dot com
2004-01-14 17:30 ` pinskia at gcc dot gnu dot org
2004-01-14 17:32 ` pinskia at gcc dot gnu dot org
2004-01-14 20:55 ` evijaykumar at yahoo dot com
2004-07-15  1:07 ` pinskia at gcc dot gnu dot org
2004-07-15  2:16 ` gianni at mariani dot ws
2004-07-15  2:42 ` bangerth at dealii dot org
2004-07-15  5:11 ` gianni at mariani dot ws
2004-07-15 11:07 ` rmerkert at alphatech dot com
2004-07-15 13:54 ` gianni at mariani dot ws
2004-08-21  0:01 ` jason at gcc dot gnu dot org
2004-08-28  2:34 ` cvs-commit at gcc dot gnu dot org
2004-08-28 10:18 ` pinskia at gcc dot gnu dot org
2004-08-28 19:04 ` gianni at mariani dot ws
2004-08-31  6:41 ` adah at netstd dot com
2004-08-31 20:58 ` pinskia at gcc dot gnu dot org
2004-09-01 16:58 ` cvs-commit at gcc dot gnu dot org
2004-09-04 18:06 ` jason at redhat dot com [this message]
2004-09-05  3:19 ` adah at netstd dot com
2005-04-13 16:56 ` dhruvbird at yahoo dot com
2005-04-14  7:39 ` jason at redhat dot com
2005-04-18  9:07 ` adah at netstd dot com
2005-04-18 18:28 ` jason at redhat dot com
     [not found] <bug-13684-4@http.gcc.gnu.org/bugzilla/>
2014-02-16 13:18 ` jackie.rosen at hushmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040904180647.14335.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).