[Issue 4624] std.stdio.File and std.typecons.Unique not GC-heap safe

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 12 09:29:26 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4624



--- Comment #1 from Michel Fortin <michel.fortin at michelf.com> 2010-08-12 12:29:25 EDT ---
Additionally, I believe std.containers.Array has a race condition when stored
in the GC heap. The Array destructor checks the reference count before deciding
whether it should free the array's content or not. This reference counter is
non-shared, but the collection cycle can run on any thread so there is a race
when accessing the reference counter.

    private struct Data
    {
        uint _refCount = 1;
        size_t _capacity;
        T[] _payload;
        this(T[] p) { _capacity = p.length; _payload = p; }
    }

The reference counter should be made shared so it is only accessed using atomic
operations. Other fields don't need to be shared because the only time they're
accessed in the destructor is when the reference counter falls to zero and the
destructor has the only remaining reference.

This problem is also present in std.stdio.File (in addition to the other
problem above) and std.typecons.RefCounted which both use a non-shared
reference counter, rendering them unsuitable for being put in the GC heap.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list