-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wip] Introduce MaybeSharedPtr type and use it for mutable objects #220
Closed
Conversation
This file contains 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
- Add a list of possible sanitizers that can be used to build the whole of podio with the USE_SANITIZER option - At the moment only build podio but do not run the tests, since there are a few things that need to be fixed before they can be succesfully run with them - Add a workflow file that builds podio with clang and gcc with all available sanitizers for the respective toolchain
Only mutable objects start with a MaybeSharedPtr<Obj> as Const objects will (almost) always be managed. Introduces a few subtle lifetime issues that have to be properly documented but should be OK for our usecases. Making Const objbects managed via a MaybeSharedPtr too would be possible, but introduces problems with cyclic dependencies
tmadlener
force-pushed
the
fix-memory-issues
branch
from
September 27, 2021 09:04
19a1b0c
to
655ccc4
Compare
Looks like builds that involve any sanitizer are not really happy with root. |
andresailer
reviewed
Oct 5, 2021
@@ -79,7 +80,10 @@ namespace podio { | |||
void readMetaDataRecord(std::shared_ptr<SIONumberedMetaDataBlock> mdBlock); | |||
void createBlocks(); | |||
|
|||
typedef std::pair<CollectionBase*, std::string> Input; | |||
/// collection, name, and flag to indictate whether it has been requested by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
/// collection, name, and flag to indictate whether it has been requested by | |
/// collection, name, and flag to indicate whether it has been requested by |
2 tasks
Superseded by #514 |
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.
BEGINRELEASENOTES
MaybeSharedPtr<T>
for usage in the mutable user facing classes viaMaybeSharedPtr<Obj>
.Obj*
inConst
classes unmanaged.clone
function always return mutable objects (keeping the same relations as the original)ObjBase
and move theObjectID
into theObj
classes.ENDRELEASENOTES
Fixes #174
The
MaybeSharedPtr
holds the managed pointer as well as a simple control block which manages its own lifetime and potentially that of the managed pointer. Ownership of the managed pointer can only move from theMaybeSharedPtr
to something else, but never the other way around (unless it has been initialized with an unmanaged pointer). This construct allows to avoid the issues in observed in #174, because the control block that decides how things should be destructed will still be around even if the managed pointer is already gone. Previously the managed pointer and the control block were one entity so this could not be guaranteed.In order to avoid too much overhead it is only used in the mutable objects but not in the immutable ones; The size of the mutable user objects doubles, since it now has two pointers instead of just one, while the one of the immutable ones remains the same.
Another important difference: The immutable objects no longer manage their
Obj*
and always assume that someone else does this for them. This should not really be a problem as in most of the cases it will be the collection that owns theObj*
. However, it could introduce some subtle lifetime issues, that could occur when a mutable object is implicitly converted to an immutable one, e.g.Making the
Const
objects also use theMaybeSharedPtr
could be done from a technical point of view, however, that leads to a problem with cyclic dependencies, e.g. here:podio/tests/unittest.cpp
Lines 112 to 126 in ed207e8
Here something an additional "weak count" (a la
std::shared_ptr
+std::weak_ptr
) would be necessary to break the cycle and ensure proper cleanup, otherwise the two references above keep each other alive indefinitely.In the end, the lifetime issues around the
Const
objects could be acceptable, if properly documented. Otherwise we might have to find a more sophisticated approach than the one proposed here.