GDC 4.8: Status of garbage collection and TLS

Johannes Pfau nospam at example.com
Sat Nov 10 10:38:17 PST 2012


Am Sat, 10 Nov 2012 09:12:55 -0800
schrieb Dan Olson <zans.is.for.cans at yahoo.com>:

> So far I am having fun gradually pushing D into apple ios sim (it runs
> i386 not arm).  I am curious though about thread local storage and GC.
> I saw older posts about it being an issue and have not seen anything
> more on it.  Is it still an issue?  I am doing all this with latest D
> git and gcc-4.8-20121028 snapshot.
> 
> What I gather is that D TLS vars are not monitored by the collector so
> memory can be prematurely collected.  Is that right?

Yes. The GC needs special runtime / compiler support to scan TLS
variables and this code has traditionally been buggy / difficult to
implement.

You can use a simple test to detect the most obvious errors:
------------------------------------------------------------
import std.stdio;
import core.memory;

class A
{
    string str;
    void a()
    {
        writeln(this.str);
    }
}

A var; //TLS variable

void main()
{
    var = new A();
    var.str = "Hello World";
    GC.collect(); //Force collection
    var.a();
}



More information about the D.gnu mailing list