www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - is there any hack to determine if variable is __gshared?

reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
Hello.

i need to enumerate all module variables of the given types (it's easy,
this is not the question) and make list of only __gshared ones. of
course, i'm talking about CTFE.

is there any hack/trick to determine if variable is __gshared? or if it
is a thread-local, for that matter?

i added 'isGShared' trait to my compiler, but i'm not expecting from
others to do the same. ;-)

the only hack i invented is this abomination:

  int v0;
  __gshared int v1;


  enum isGShared(alias var) =3D
    !__traits(compiles,
      mixin("{auto a___ =3D function typeof("~var.stringof~
            ") ()  safe { return "~var.stringof~"; };}"));


  pragma(msg, isGShared!v0); // false
  pragma(msg, isGShared!v1); // true


sure, it's very limited, and we must do alot of checks before using it.
it *SEEMS* to work, but i not tested it very well.
Oct 13 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
ketmar:

 is there any hack/trick to determine if variable is __gshared? 
 or if it is a thread-local, for that matter?
There is the -vtls compiler switch. Bye, bearophile
Oct 13 2014
parent ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 13 Oct 2014 15:57:13 +0000
bearophile via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
wrote:

 is there any hack/trick to determine if variable is __gshared?=20
 or if it is a thread-local, for that matter?
=20 There is the -vtls compiler switch.
let me quote myself: "i'm talking about CTFE". i need to build mixin string with this variables, to be precise.
Oct 13 2014