On Thu, Jan 4, 2018 at 3:18 PM, Nathaniel Smith <njs at pobox.com> wrote:
> I think the fix is a little bit cumbersome, but straightforward, and
> actually *simplifies* caching.
[...]
> And then the caching in get() becomes:
>> def get(self):
> if tstate->current_context != self->last_context:
> # Update cache
> self->last_value = tstate->current_context_data->hamt_lookup(self)
> self->last_context = tstate->current_context
> return self->last_value
Actually, this trick of using the Context* as the cache validation key
doesn't work :-/. The problem is that the cache doesn't hold a strong
reference to the Context, so there's an ABA problem [1] if the Context
is deallocated, and then later the same memory location gets used for
a new Context object. It could be fixed by using weakref callbacks,
but that's not really simpler than the current counter-based cache
validation logic.
-n
[1] https://en.wikipedia.org/wiki/ABA_problem
--
Nathaniel J. Smith -- https://vorpus.org