DIP18: Non-GC threads

Piotr Szturmaj bncrbme at jadamspam.pl
Sat Sep 1 04:54:10 PDT 2012


Michel Fortin wrote:
>> If some of the function's arguments take references (directly or
>> indirectly), then all of them are automatically added to the list of
>> GC roots (addRoot()).
>
> You still have a problem: you might have added an object passed as an
> argument to the GC roots, preventing the GC from collecting it, but if
> any thread is allowed to mutate a pointer inside this object pointing to
> some other data, using this other data in your thread is not safe,
> unless you have added a root for this other pointer too. You'd have to
> recursively add roots for this to work.
>
> There's also the same issue with global variables, the ones which are
> pointers to other pointers.

Yes, there is no obvious solution, but I think it could be done. For 
example non-immutable references may be disallowed at all. The other 
solution is to copy the whole referenced object using malloc, and add it 
to the GC roots.


More information about the Digitalmars-d mailing list