This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [c++0x] thread_local
- From: "Chris Fairles" <chris dot fairles at gmail dot com>
- To: "GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 5 Sep 2008 14:11:07 -0400
- Subject: Re: [c++0x] thread_local
- References: <fac6bb500809050624o1c877dbfpcd9249ab446f624d@mail.gmail.com>
On Fri, Sep 5, 2008 at 9:24 AM, Chris Fairles <chris.fairles@gmail.com> wrote:
> Just curious if thread_local could "piggy back" __thread (well,
> RID_THREAD really). I've never really modified the c/c++ front-end so
> I'm not aware of the big picture but the attached patch has a trivial
> test case that passes (and thus far I can't see any regressions caused
> by the patch, on x64_64-unknown-linux anyway).
>
> Is it really this simple? If so, I can whip up some testcases and a
> changelog entry.
>
Well, I didn't think it would be that easy and I was right:
void foo() {
thread_local int i;
}
error: function-scope 'i' implicitly auto and declared '__thread'
> Cheers,
> Chris
>
> PS. Just FYI here's some code I was using for a slightly-less-trivial
> testcase. Unfortunately it uses a local libstdc++ <thread>
> implementation I haven't submitted yet but you could modify it to use
> boost.thread or pthreads if you're so inclined to see it work ;)
>
> #include <thread>
>
> thread_local int j = 42;
>
> void foo() { j = 43; }
>
> int main()
> {
> std::thread t(foo);
> t.join();
>
> if(j != 42) abort();
>
> return 0;
> }
>