Add per-allocator mutex for transfer_all/transfer_free#8
Merged
Conversation
Each PoolAllocator now has its own std::mutex (transfer_mutex). transfer_all and transfer_free lock only the destination's mutex, since the source is assumed to be accessed only by its owning thread. This avoids deadlocks (only one mutex locked at a time) while protecting the destination when multiple threads transfer concurrently. Also fix lcov coverage mismatch error with gcov-13 templates by adding --ignore-errors mismatch to the coverage capture command. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
d05854c to
f242af5
Compare
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
Each
PoolAllocatornow has its ownstd::mutex(transfer_mutex).transfer_allandtransfer_freelock only the destination's mutex before mutating its internal state.The source allocator is not locked — it is assumed to be accessed only by its owning thread (typically a
thread_localinstance being emptied before the thread exits).Why destination-only locking?
Changes
pool_allocator.h: Add#include <mutex>, addmutable std::mutex transfer_mutexprivate member, update doc commentspool_allocator.tcc: Addstd::lock_guardintransfer_allandtransfer_freeTest plan