From 9174a8f7e70163e29e0b02f578340b98e4727ced Mon Sep 17 00:00:00 2001 From: Stefano Date: Fri, 29 Mar 2024 17:17:26 +0100 Subject: [PATCH] Avoid deadlock issues when attempting to close a device implementing the service interface Apparently, when the signal handler was setting the static flag "terminated" to false, it was also attempting to close immediately the terminator port, but this was receiving the termination message and some race condition seemed to occur on Windows --- src/libYARP_dev/src/yarp/dev/Drivers.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libYARP_dev/src/yarp/dev/Drivers.cpp b/src/libYARP_dev/src/yarp/dev/Drivers.cpp index 88d60503548..b4ea95f1b68 100644 --- a/src/libYARP_dev/src/yarp/dev/Drivers.cpp +++ b/src/libYARP_dev/src/yarp/dev/Drivers.cpp @@ -325,7 +325,6 @@ DriverCreator* Drivers::Private::load(const char *name) { } static std::string terminatorKey; -static bool terminated = false; static void handler (int) { Time::useSystemClock(); @@ -343,7 +342,6 @@ static void handler (int) } if (!terminatorKey.empty()) { yCInfo(DRIVERS, "[try %d of 3] Trying to shut down %s", ct, terminatorKey.c_str()); - terminated = true; Terminator::terminateByName(terminatorKey.c_str()); } else { yCInfo(DRIVERS, "Aborting..."); @@ -529,6 +527,7 @@ int Drivers::yarpdev(int argc, char *argv[]) { service = nullptr; } } + bool terminated = false; while (dd.isValid() && !(terminated||(terminee&&terminee->mustQuit()))) { if (service!=nullptr) { double now = Time::now();