Hi all, I recently integrated Mosquitto into a C++ app but I'm wondering if my design is faulty:
The app is currently using UDP for communication, and I'm experimenting with MQTT. The existing design creates a thread for every socket, and constructs, runs, and destructs the socket in that thread. I used the same pattern for Mosquitto: The Mosquitto lib is initialized and destroyed in the main thread (i.e. mosquitto_lib_init(), mosquitto_lib_cleanup()), but every time I want to create a new Mosquitto client (i.e. mosquitto_new()), I first start a thread, and the client exists solely in that thread.
This works fine in practice, at least so far, but it occurs to me I have no idea if it's safe to be creating and running the Mosquitto clients in different threads than the library was initialized. Does anyone know?
As an aside, I saw that you can run the loop asynchronously. I haven't done that because my main thread is performance critical, so I'd like to keep all processing related to message sending out of it. But if that's the only way to make it async and thread safe, I'll go that route.
thanks much!