Comment 4 for bug 420738

Revision history for this message
John A Meinel (jameinel) wrote :

Aaron-

I just ran into something like this in my multi-threaded testing of parts of bzrlib.

Suffice it to say that LRUCache is *not* thread safe. It is probably close, but it doesn't have atomic operations. So stuff like:

# Remove from the double-linked list
node.next.prev = node.prev
node.prev.next = node.next

Has the potential to switch threads in between those two statements, and you end up with a corrupted double-linked list.

At the moment, I don't have plans to make LRUCache threadsafe. You could do it with 'one-big-lock' on the datastructure, I suppose.

I'd probably rather write a C/Pyrex implementation that would perform approx as fast as a regular dict, and then look into making *that* threadsafe. Note that python dicts themselves aren't threadsafe anyway, as python used the GIL to avoid putting a lock on every object. (Or spinlocking the refcount, etc.)