
12 Apr
2009
12 Apr
'09
1:24 p.m.
JOAQUIN M. LOPEZ MUÑOZ:
This does not work because of scenarios like the following:
1. Thread A detaches the last reference to x and is preempted when it's about to enter erase. 2. Thread B retrieves x so that its refcount is now 1. After some work with x, thread B detaches the reference to x, whose refcount drops again to zero, enters erase and eliminates x. 3. Thread A resumes, but erase now attempts to work with a nonexistent x.
Here by x you mean the refcounted_value, I guess. Yes, this doesn't work if 'Handle' is a raw pointer, for example. I think, however, that it does work if erase doesn't need to dereference the handle in order to see that it's already been removed.