Skip to content

Bump the generation when a read promotes an LRUCache entry - #76

Merged
awolverp merged 1 commit into
awolverp:mainfrom
Malkiz223:lru_read_promotion
Aug 10, 2026
Merged

Bump the generation when a read promotes an LRUCache entry#76
awolverp merged 1 commit into
awolverp:mainfrom
Malkiz223:lru_read_promotion

Conversation

@Malkiz223

Copy link
Copy Markdown
Contributor

Closes #75

LRUPolicy::get moved the entry to the back of the list without bumping the generation, so a live iterator kept walking the relinked list and the process died. Now a promoting read bumps the generation, and a live iterator raises the same RuntimeError it already raises after an insert. A hit on the most recent entry moves nothing, so it does not bump either: iterating is still safe around it, and the pointless unlink-relink it used to do is gone.

PolicyExt::get takes shared now, the same way entry already does; only the LRU policy uses it, the others ignore it.

No answers change, eviction order stays exactly the same. A promoting hit pays one atomic increment, 3 ns on my machine; a hit on the most recent entry and misses cost what they cost before.

The test runs the walk in a child process on purpose: without the fix it dies instead of failing.

@awolverp
awolverp merged commit c2d05d1 into awolverp:main Aug 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reading from an LRUCache while iterating it crashes the process

2 participants