Repository navigation
fix(cache): synchronize _ensure_eviction_task execution with threading.Lock (#133) - #143
Merged
alialfostovar merged 2 commits intoOct 20, 2026
Conversation
alialfostovar
approved these changes
Oct 20, 2026
alialfostovar
left a comment
Contributor
There was a problem hiding this comment.
Hi @dwaddle,
Wow, this is an exceptionally clean implementation of the double-checked locking pattern! The test with threading.Barrier(20) is brilliant and ensures rock-solid thread safety.
I was actually touching this area last night, but your approach and test suite are far superior and more robust.
Approving and merging this into release/v0.1.0-rc.3. Thank you for elevating the quality of ZCore! 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses #133 by guarding background memory eviction task creation in
zcore.cache.basewith athreading.Lockdouble-checked initialization pattern.Changes
_eviction_lock = threading.Lock()inzcore.cache.base. In_ensure_eviction_task(), the loop check andloop.create_task(_start_eviction_loop(...))assignment are guarded viawith _eviction_lock:with double-checked verification.close_cache(): Wrapped_eviction_taskretrieval and clearing insidewith _eviction_lock:to prevent concurrent threads from scheduling a new task while shutdown is in flight.test_ensure_eviction_task_concurrent_thread_safetyintests/test_cache.pyexercising concurrent invocation across 20 threads to guarantee exactly one eviction loop task is spawned.Verification
uv run ruff format --check: Passed cleanly.uv run ruff check: Passed cleanly.uv run --all-extras pytest: 516/516 passed.Closes #133.