A Refcounted Array Type

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 3 06:42:39 PST 2015


On 3/3/15 9:22 AM, Kagamin wrote:
> On Saturday, 28 February 2015 at 04:18:38 UTC, ketmar wrote:
>>> His case is not @safe, so we can ignore that problem.
>>
>> the compiler tends to disagree:
>>
>> === test.d ===
>> int myglobal;
>>
>> class A {
>>   ~this () @safe { if (myglobal == 42) assert(0); }
>> }
>>
>> void main () {
>>   auto a = new A;
>> }
>> ======
>>
>> dmd -w -c -o- test.d
>>
>> wow! no warnings, no errors!
>
> And what's the problem?

This:

void main()
{
    myglobal = 42;
    spawnThread((){myglobal = 0; auto a = new A; a = null; while(1){}});

    // trigger assert in A.dtor.
    int[] mem;
    while(1)
    {
       mem.length += 10000;
    }
}

-Steve


More information about the Digitalmars-d mailing list