diff --git a/common/common.h b/common/common.h index c045cfea..e5e1ca02 100644 --- a/common/common.h +++ b/common/common.h @@ -66,6 +66,7 @@ namespace Common { private: zmqpp::context &_context; zmqpp::socket _socket; + mutable std::mutex _publish_mtx; Mode _mode; ///< publisher or subscriber? std::string _topic; ///< publisher topic std::vector _topics; ///< list of subscriber topics @@ -179,6 +180,7 @@ namespace Common { if ( _mode != Mode::PUB ) { throw std::runtime_error( "(Common::PubSub::publish) not a publisher" ); } + std::lock_guard lock( _publish_mtx ); zmqpp::message message_zmq; // Publish to either class default _topic or topic specified as // optional arg.