www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - __gshared and static constructors

reply =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
Hi,

When using __gshared for variables at module level, it is my 
understanding that they should be initialized in the shared static this 
constructor. My question is: When having __gshared variables inside 
classes, where should I initialize these? Do classes have a shared 
static this constructor?

- Alex
Jan 04 2012
next sibling parent Mike Parker <aldacron gmail.com> writes:
On 1/5/2012 4:14 AM, Alex Rønne Petersen wrote:
 Hi,

 When using __gshared for variables at module level, it is my
 understanding that they should be initialized in the shared static this
 constructor. My question is: When having __gshared variables inside
 classes, where should I initialize these? Do classes have a shared
 static this constructor?

 - Alex
Yes. You can also use a module constructor, since all class members are be visible to the module.
Jan 04 2012
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-01-04 20:14, Alex Rønne Petersen wrote:
 Hi,

 When using __gshared for variables at module level, it is my
 understanding that they should be initialized in the shared static this
 constructor. My question is: When having __gshared variables inside
 classes, where should I initialize these? Do classes have a shared
 static this constructor?

 - Alex
I don't think there's much difference between a module constructor and a static class constructor. I think that second is just scoped in the class. -- /Jacob Carlborg
Jan 04 2012