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.
Under certain conditions (compilers, time of day, user mood...), ngen with python support active would hit a segmentation fault at the end of
main
, during the destruction/cleanup of the program. This was first observed in #370 and has recently been seen even outside of the parallel runtime. As noted in that issue, the static singleton used across multiple compilation units is likely to blame, as the the destruction order of resources is not guaranteed.This PR addresses this problem while maintaining a static global interpreter util by using a
weak_ptr
as the static resource, and then constructingshared_ptr
objects as the singletoninstances
. Theweak_ptr
ref counting prevents the destruction the of the underlying util class, which contains thepy::scoped_interpreter
that defines the lifecycle of the python interpreter.Note that if an instance is called but not referenced
utils::ngenPy::InterpreterUtil::getInstance();
then the interpreter is started and finalized, as there is no reference to count. In this case, the next call to
getInstance()
creates and initializes a NEW interpreter.In contrast, if the reference is held
auto a = utils::ngenPy::InterpreterUtil::getInstance();
then the next call to
getInstance()
returns a shared pointer to the existing interpreter.I also added a reference to the
Routing_Py_Adapter
class to ensure that it always had a valid interpreter available, instead of relying strictly on the assumption that someone created and was holding a reference at the right scope for it to operate.Changes
InterpreterUtil
to use a ref-counting mechanism.Testing
Notes
Todos
Checklist
Target Environment support
Closes #370