From d0ed2943246b5bc5260e452993e7d287c508acc4 Mon Sep 17 00:00:00 2001
From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es>
Date: Tue, 7 Nov 2017 02:24:56 +0100
Subject: [PATCH] Add some more extra thread safety to the network events
 module

---
 Source/Plugins/NetworkEvents/NetworkEvents.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Source/Plugins/NetworkEvents/NetworkEvents.cpp b/Source/Plugins/NetworkEvents/NetworkEvents.cpp
index 38efd1b84..a623166e6 100644
--- a/Source/Plugins/NetworkEvents/NetworkEvents.cpp
+++ b/Source/Plugins/NetworkEvents/NetworkEvents.cpp
@@ -212,9 +212,11 @@ bool NetworkEvents::closesocket()
 #ifdef ZEROMQ
     if (threadRunning)
     {
+		lock.enter();
         zmq_close (responder);
         zmq_ctx_destroy (zmqcontext); // this will cause the thread to exit
         zmqcontext = nullptr;
+		lock.exit();
 
 		if (!stopThread(500))
 		{
@@ -572,7 +574,9 @@ void NetworkEvents::run()
 
     while (threadRunning)
     {
+		lock.enter();
         result = zmq_recv (responder, buffer, MAX_MESSAGE_LENGTH - 1, 0);  // blocking
+		lock.exit();
 
         juce::int64 timestamp_software = timer.getHighResolutionTicks();
 
@@ -664,8 +668,10 @@ void NetworkEvents::loadCustomParametersFromXml()
 void NetworkEvents::createZmqContext()
 {
 #ifdef ZEROMQ
+	lock.enter();
     if (zmqcontext == nullptr)
         zmqcontext = zmq_ctx_new(); //<-- this is only available in version 3+
+	lock.exit();
 #endif
 }
 
-- 
GitLab