Add force_unlock() to allocator_storage.#195
Open
jodyhagins wants to merge 2 commits intofoonathan:mainfrom
Open
Add force_unlock() to allocator_storage.#195jodyhagins wants to merge 2 commits intofoonathan:mainfrom
jodyhagins wants to merge 2 commits intofoonathan:mainfrom
Conversation
added 2 commits
August 27, 2025 11:13
This feature is almost never needed. However, when it is needed, it is badly needed. Consider the case where a program forks. The allowable operations in the child (before calling exec) are very limited. However, we might want to use a special purpose allocator. But, if that allocator can be used my multiple threads, then it is possible that one of those threads is holding the lock when fork is called. This means that the child can't acquire the lock because the thread holding it will never get to run and release the lock within the child process. In this case, the child must be able to unlock the allocator. This is, admittedly, a very exceptional use case. However, it has been added in such a way that it will only appear in the API if the provided Mutex type supports `force_unlock`, which is unlikely for most use cases. The only other way of accomplishing this task is using nasty techniques to subvert the visibility access rules of the language since the mutex is one of multiple a private base classes. Another small change to support this feature was to add a member access through pointer operator to the mutex storage classes.
allocator_storage takes a Mutex type supports force_unlock() but when the allocator is stateless, the actual mutex type will be no_mutex instead of the supported one. We could SFINAE on teh passed-in mutex type, and then detect the no_mutex type and turn it into a no-op. However, it doesn't seem like a bad thing to just add force_unlock() to the no_mutex types, since there is no locking going on anyway.
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.
This feature is almost never needed. However, when it is needed, it is badly needed.
Consider the case where a program forks. The allowable operations in the child (before calling exec) are very limited. However, we might want to use a special purpose allocator. But, if that allocator can be used my multiple threads, then it is possible that one of those threads is holding the lock when fork is called. This means that the child can't acquire the lock because the thread holding it will never get to run and release the lock within the child process.
In this case, the child must be able to unlock the allocator.
This is, admittedly, a very exceptional use case. However, it has been added in such a way that it will only appear in the API if the provided Mutex type supports
force_unlock, which is unlikely for most use cases.The only other way of accomplishing this task is using nasty techniques to subvert the visibility access rules of the language since the mutex is one of multiple a private base classes.
Another small change to support this feature was to add a member access through pointer operator to the mutex storage classes.