On 10.11.2014 15:19, Steven Schveighoffer wrote:

Now, imagine you wanted to put this on the GC heap, and the GC would
call struct dtors. And let's say the program is multi-threaded. First,
the memory referred to by t isn't guaranteed to be alive, it could have
already been finalized and freed. Second, the thread that calls the
destructor may not be the thread that owns t. This means that two
threads could potentially be calling t.inc() or t.dec() at the same
time, leading to race conditions.

So, would you object to actually call the destructor for GC collected structs? I don't think that threading problems in the implmentation of the destructor should prohibit this.

The reference count in your example also doesn't work for heap allocated structs that are never collected or for structs inside classes.

The pull request is almost ready to be merged, please chime in: https://github.com/D-Programming-Language/druntime/pull/864

Reply via email to