public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Guenther <richard.guenther@gmail.com>
Cc: Jason Merrill <jason@redhat.com>,
	       gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: RFC: C++ PATCH to support dynamic initialization and destruction of C++11 and OpenMP TLS variables
Date: Fri, 05 Oct 2012 08:41:00 -0000	[thread overview]
Message-ID: <20121005084139.GI1787@tucnak.redhat.com> (raw)
In-Reply-To: <CAFiYyc1VSgAV5OdtQmZXKB2-=TvBU1tnBmedJXWdrn46eJDPRQ@mail.gmail.com>

On Fri, Oct 05, 2012 at 10:29:54AM +0200, Richard Guenther wrote:
> I wonder if an implementation is conforming that performs non-local TLS
> variable inits at thread creation time instead (probably also would require
> glibc support)?

I think it is conforming, but not really doable, because of dlopen.
If you have multiple threads running already and dlopen a library that has
thread_local with ctors, you can construct them in the current thread, but
can't construct them in other threads (even just sending some magic syscall,
interrupting those threads, isn't going to work, because then you'd be in
async-signal context where the number of things you can portably do is
limited, while the constructors can expect to be able to execute arbitrary
code).  This is similar to the reason why we want to make libraries
which have thread_local with dtors non-dlcloseable.  We can destruct in the
current thread at dlclose time, but can't destruct in other threads (and the
C++ standard isn't aware of dlclose, therefore it can't easily say anything
allowing the dtors not to be run in that case).  thread_local dtors for
other threads (from what Jason said, haven't checked the standard) don't
need to run for other threads at exit time (which is a situation very
similar to dlclose).

> Should we document our choice of implementation somewhere in the
> manual?  And thus implicitely provide the hint that using non-local TLS
> variables with dynamic initialization comes with an abstraction penalty
> that we might not be easily able to remove?

Unfortunately, that penalty is not only for thread_local vars with
ctors/dtors.  There is some penalty even for using
extern thread_local int i;
int foo (void)
{
  return i;
}
(as compared to extern __thread int i;), because we have to at least check
whether the weak TLS initializer for i is NULL or not.  Other TU could have
thread_local int i = dynamic_initialization ();

	Jakub

  reply	other threads:[~2012-10-05  8:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-04 17:39 Jason Merrill
2012-10-05  8:30 ` Richard Guenther
2012-10-05  8:41   ` Jakub Jelinek [this message]
2012-10-05 17:28     ` Jason Merrill
2012-10-05 17:38   ` Jason Merrill
2012-10-15 17:49     ` Jason Merrill
2012-10-05  8:31 ` Jakub Jelinek
2012-10-09 14:08 Dominique Dhumieres
2012-10-09 14:43 ` Jack Howarth
2012-10-09 15:28   ` Jason Merrill
2012-10-09 16:28     ` Dominique Dhumieres
2012-10-09 20:43     ` Dominique Dhumieres
2012-10-10  1:16       ` Jason Merrill
2012-10-10 13:27         ` Jack Howarth
2012-10-10 14:54           ` Rainer Orth
2012-10-10 20:20             ` Jack Howarth
2012-10-10 20:25               ` Jack Howarth
2012-10-11 15:23     ` Jason Merrill
2012-10-10 15:01 ` Rainer Orth
2012-10-15 20:25 ` Richard Sandiford

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=20121005084139.GI1787@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=richard.guenther@gmail.com \
    /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).