Thread-local Member Variables?

dsimcha dsimcha at yahoo.com
Wed Jan 13 13:55:06 PST 2010


== Quote from Nick Sabalausky (a at a.a)'s article
> "dsimcha" <dsimcha at yahoo.com> wrote in message
> news:hikj7a$18lq$1 at digitalmars.com...
> > Should there be a way, in D, to create a variable that's local to both a
> > thread and a class instance?  For example:
> >
> > class Foo {
> >    __thread uint num;
> > }
> >
> > num would basically be a reference to thread-local storage, with a new one
> > created for every instance of Foo.  Is there a (non-hacky) way to do this
> > already?
> How would that be different from doing this in D2?:
> class Foo {
>    uint num;
> }
> 'num' isn't declared as static, so a new one is created for every instance
> of Foo, and 'shared' isn't used so it's thread local. Am I missing
> something?

No, the thread-local by default thing only applies to globals and statics.



More information about the Digitalmars-d mailing list