Workaround for typeid access violation

Etienne Cimon via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 18 05:08:10 PDT 2015


On Thursday, 18 June 2015 at 11:43:18 UTC, ketmar wrote:
> On Wed, 17 Jun 2015 22:35:12 +0000, Etienne Cimon wrote:
>
>> e.g. __gshared MyObj g_obj1;
>> 
>> Thread 1: g_obj1 = new MyObj;
>> Thread 2: g_obj1.obj2 = new MyObj;
>> Thread 3: write(g_obj1.obj2); <-- access violation (probably)
>
> so no way to anchor the whole object tree by assigning it to 
> __gshared root? sure, this will never make it into mainline.

__gshared is a little sketchy. We can have TLS GC by default by 
piping `new shared` to a shared GC. It's even safer, because then 
we have the type system helping out.

e.g. shared MyObj g_obj1;
Thread 1: g_obj1 = new shared MyObj;
Thread 2: g_obj1.obj2 = new shared MyObj;
Thread 3: write(g_obj1.obj2); <-- success!


More information about the Digitalmars-d mailing list