draft proposal for ref counting in D
Walter Bright
newshound2 at digitalmars.com
Wed Oct 9 19:28:14 PDT 2013
Steven Schveighoffer wrote:
On Jun 30, 2013, at 8:18 PM, Walter Bright wrote:
>
> I very much want to avoid requiring atomic counts - it's a major performance
penalty. Note that if the GC is reaping a cycle, nobody else is referencing the
object, so this should not be an issue.
I think you didn't understand what Michel was saying.
Take for example:
A->B->C->A
this is a cycle. Imagine that nobody else is pointing at A, B or C. Fine. The
GC starts to collect this cycle.
But let's say that D is not being collected *AND* B has a reference to D.
B could be getting destroyed in one thread, and decrementing D's reference
count, while someone else in another thread is incrementing/decrementing D's
reference count.
I agree that RC optimally is thread-local. But if you involve the GC, then ref
incs and decs have to be atomic.
I don't think this is that bad. iOS on ARM which has terrible atomic primitives
uses atomic reference counts.
If you do NOT involve the GC and are careful about cycles, then you could
potentially have a RC solution that does not require atomics. But that would
have to be a special case, with the danger of having cycles.
-Steve
More information about the Digitalmars-d
mailing list