Skip to content
Snippets Groups Projects
Commit c005dd83 authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

fix shutdown issues when waiting for devices (cf. #10029)

parent 8a5a47c1
No related branches found
No related tags found
No related merge requests found
......@@ -130,6 +130,8 @@ namespace ChimeraTK {
*/
[[nodiscard]] Device& getDevice() { return _device; }
void terminate() override;
protected:
/**
* Use this function to read the exception version number. It is locking the variable mutex correctly for you.
......
......@@ -185,6 +185,12 @@ void Application::shutdown() {
internalModule->deactivate();
}
// shutdown all DeviceManagers, otherwise application modules might hang if still waiting for initial values from
// devices
for(auto& pair : _deviceManagerMap) {
pair.second->terminate();
}
// next deactivate the modules, as they have running threads inside as well
for(auto& module : getSubmoduleListRecursive()) {
module->terminate();
......
......@@ -398,4 +398,26 @@ namespace ChimeraTK {
/*********************************************************************************************************************/
void DeviceManager::terminate() {
if(moduleThread.joinable()) {
moduleThread.interrupt();
// try joining the thread
while(!moduleThread.try_join_for(boost::chrono::milliseconds(10))) {
// send boost interrupted exception through the _errorQueue
try {
throw boost::thread_interrupted();
}
catch(boost::thread_interrupted&) {
_errorQueue.push_exception(std::current_exception());
}
// it may not suffice to send the exception once, as the exception might get overwritten in the queue, thus we
// repeat this until the thread was joined.
}
}
assert(!moduleThread.joinable());
}
/*********************************************************************************************************************/
} // namespace ChimeraTK
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment