-
Notifications
You must be signed in to change notification settings - Fork 1
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
Re-init ServiceRegistry on every Initialize() call #63
base: master
Are you sure you want to change the base?
Conversation
Without this, the sequence of calls xacc::Initialize() xacc::Finalize() xacc::Initialize() will cause CppMicroservices to throw the following: terminate called after throwing an instance of 'std::runtime_error' what(): The bundle context is no longer valid
Thanks @ausbin. This seems such an edge case. I'm curious when one would ever use/need the following.
|
@@ -60,6 +60,7 @@ void ServiceAPI_Finalize() { | |||
if (serviceAPIInitialized) { | |||
serviceAPIInitialized = false; | |||
serviceRegistry->finalize(); | |||
serviceRegistry.release(); |
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.
release
gives up the pointer for someone else to hold on to (in this case, it's leaking memory). I think you want reset
or = {}
or = nullptr
.
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.
Thanks, will fix.
I also will look into why the tests are segfaulting. I wonder if something is accessing the service registry after finalize()
Good point @danclaudino. Is that sequence of calls even supported? I assumed so, but if you are only supposed to call If this is meant to be supported, I will investigate the Python segfault further (I looked a bit and some Python code is indeed touching the ServiceRegistry before |
@danclaudino Is the expectation that you only execute one quantum circuit for every use of XACC? Or that you're supposed to assume that you're the only library in a larger toolchain that uses XACC (and thus only your library will ever call init/finalize)? If Finalize doesn't finalize, why bother having it at all? Maybe it would be better to just "initialize" the global variables once and then have an The usual reason to have multiple initialize/finalize is to reset states for reproducibility, unit testing, etc. |
Without this, the sequence of calls
will cause CppMicroservices to throw the following:
Testing
I ran
ctest
and did some end-to-end testing with QIR-EE.