This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [c++0x] thread_local


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;
> }
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]