From ec1cc9a97f9cd62e42b1535b1bdffd27a8f6bfab Mon Sep 17 00:00:00 2001 From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es> Date: Tue, 7 Nov 2017 02:20:35 +0100 Subject: [PATCH] Add some extra thread safety to the network events module --- Source/Plugins/NetworkEvents/NetworkEvents.cpp | 6 ++++++ Source/Plugins/NetworkEvents/NetworkEvents.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.cpp b/Source/Plugins/NetworkEvents/NetworkEvents.cpp index 2e36d150b..38efd1b84 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.cpp +++ b/Source/Plugins/NetworkEvents/NetworkEvents.cpp @@ -216,8 +216,14 @@ bool NetworkEvents::closesocket() zmq_ctx_destroy (zmqcontext); // this will cause the thread to exit zmqcontext = nullptr; + if (!stopThread(500)) + { + std::cerr << "Network thread timeout. Forcing thread termination, system could be lefr in an unstable state" << std::endl; + } + if (! shutdown) createZmqContext();// and this will take care that processor graph doesn't attempt to delete the context again + } #endif return true; diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.h b/Source/Plugins/NetworkEvents/NetworkEvents.h index a8388a044..1f92a2822 100644 --- a/Source/Plugins/NetworkEvents/NetworkEvents.h +++ b/Source/Plugins/NetworkEvents/NetworkEvents.h @@ -117,7 +117,7 @@ public: int urlport; String socketStatus; - bool threadRunning; + std::atomic<bool> threadRunning; private: -- GitLab