On Thursday, 17 October 2013 at 08:09:24 UTC, Martin Nowak wrote:
On 10/13/2013 09:47 AM, Denis Shelomovskij wrote:
* Alex's one from MCI:
https://github.com/lycus/mci/blob/f9165c287f92e4ef70674828fbadb33ee3967547/src/mci/core/weak.d
I remember talking about this with Alex.
He wanted to add some functions to the GC and this is what I
came up with based on the current implementation.
It uses the synchronized GC.addrOf to check whether the loaded
pointer is still valid.
I'm afraid this is insufficient. If a same-sized block is
allocated before the dispose event is triggered, the WeakRef
could end up pointing to something else. It's a rare case (in
the current GC, a finalizer would have to do the allocation), but
possible. This is what I referred to as the ABA problem the
other day. Not strictly accurate, but the effect is similar.