diff --git a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp index 45d8f734ddc393c387cfdfb2700390ec30c64612..c8ff8749204a1d35457e9e5b07e9e4b3faecfc45 100644 --- a/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp +++ b/source/RobotAPI/components/units/RobotUnit/NJointControllers/NJointController.cpp @@ -295,17 +295,22 @@ namespace armarx NJointController::~NJointController() { // make sure the destructor of the handles does not throw an exception and triggers a termination of the process - try + ARMARX_DEBUG << "Deleting thread handles"; + ScopedLock lock(threadHandlesMutex); + for (auto& pair : threadHandles) { - ARMARX_DEBUG << "Deleting thread handles"; - ScopedLock lock(threadHandlesMutex); - for (auto& pair : threadHandles) + try { + auto& name = pair.first; auto& handle = pair.second; - if (!handle) + if (!handle || !handle->isValid()) + { + ARMARX_VERBOSE << "Thread Handle is NULL or invalid - skipping"; + continue; + } + if (handle->isDetached()) { - ARMARX_VERBOSE << "Thread Handle is NULL - skipping"; continue; } std::future_status status; @@ -325,14 +330,15 @@ namespace armarx } while (status != std::future_status::ready); } + catch (...) + { + handleExceptions(); + } + } + + threadHandles.clear(); - threadHandles.clear(); - } - catch (...) - { - handleExceptions(); - } } ControlTargetBase* NJointController::useControlTarget(const std::string& deviceName, const std::string& controlMode)