[Python-Dev] PEP 567 v2 (original) (raw)

Nathaniel Smith njs at pobox.com
Fri Jan 5 18:26:42 EST 2018


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->currentcontext != self->lastcontext: # Update cache self->lastvalue = tstate->currentcontextdata->hamtlookup(self) self->lastcontext = tstate->currentcontext return self->lastvalue

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



More information about the Python-Dev mailing list