Testing some singleton implementations

luka8088 luka8088 at owave.net
Mon Feb 10 05:25:21 PST 2014


On 10.2.2014. 13:44, luka8088 wrote:
> On 10.2.2014. 10:54, Andrej Mitrovic wrote:
>> On 2/9/14, luka8088 <luka8088 at owave.net> wrote:
>>>   private static __gshared typeof(this) instance_;
>>
>> Also, "static __gshared" is really meaningless here, it's either
>> static (TLS), or globally shared, either way it's not a class
>> instance, so you can type __gshared alone here. Otherwise I'm not sure
>> what the semantics of a per-class-instance __gshared field would be,
>> if that can exist.
>>
> 
> "static" does not meat it must be tls, as "static shared" is valid.
> 
> I just like to write that it is static and not shared. I know that
> __gshared does imply static but this implication is not intuitive to me
> so I write it explicitly.
> 
> For example, I think that the following code should output 5 and 6 (as
> it would it __gshared did not imply static):
> 
> 
> module program;
> 
> import std.stdio;
> import core.thread;
> 
> class A {
>   __gshared int i;
> }
> 
> void main () {
> 
>   auto a1 = new A();
>   auto a2 = new A();
> 
>   (new Thread({
>     a1.i = 5;
>     a2.i = 6;
>     (new Thread({
>       writeln(a1.i);
>       writeln(a2.i);
>     })).start();
>   })).start();
> 
> }
> 
> 
> But in any case, this variable is just __gshared.
> 

Um actually this makes no sense. But anyway I mark it static.



More information about the Digitalmars-d mailing list