public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Daniel Lohmann <daniel.lohmann@informatik.uni-erlangen.de>
To: John Love-Jensen <eljay@adobe.com>
Cc: MSX to GCC <gcc-help@gcc.gnu.org>
Subject: Re: G++ and constructors
Date: Wed, 07 Mar 2007 16:40:00 -0000	[thread overview]
Message-ID: <45EEE953.3090409@informatik.uni-erlangen.de> (raw)
In-Reply-To: <C212BE33.1D26D%eljay@adobe.com>

John Love-Jensen schrieb:
> [...] 
> Although you didn't ask for work-arounds, here's a work-around that works
> for GCC, but may not work in C++ in general*.
> 
> GCC uses threading protection for static objects.
> 
> So this variant of your routine, in GCC, should be thread safe:
> 
> ----------------------------------------------------------------------
> myclass* myclass::init_instance() // private: static
> {
>   return new myclass();
> }
> 
> myclass* myclass::get_instance() // public: static
> {
>   static myclass* instance = InitInstance();
>   return instance;
> }
> ----------------------------------------------------------------------

*GCC* does the threading protection?

I really wonder how!

How can GCC achieve this on every platform (especially embedded targets 
such as AVR, H8, ARM) without help from the runtime? (I haven't seen any 
dependencies to RTL functions in such case.)

Is this implemented using interruption-transparent algorithms / atomic 
operations or does the above simply hold only for some specific platform?


Daniel

  parent reply	other threads:[~2007-03-07 16:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-06  2:37 Sean MacLennan
2007-03-06 12:46 ` John Love-Jensen
2007-03-06 14:58   ` John Love-Jensen
2007-03-07 16:40   ` Daniel Lohmann [this message]
2007-03-08 17:16     ` Ian Lance Taylor

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=45EEE953.3090409@informatik.uni-erlangen.de \
    --to=daniel.lohmann@informatik.uni-erlangen.de \
    --cc=eljay@adobe.com \
    --cc=gcc-help@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).