Skip to content

Conversation

jodyhagins
Copy link

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.

Jody Hagins 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.
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.

1 participant