|[paho-dev] Simultaneous sub/pub-instances|
Hi Paho team,
Thank you for a great MQTT library! I’m using the org.eclipse.paho.mqtt.c library.
In a project connecting existing devices to the Internet, I want a service (on the Internet) to be able to receive messages from devices, but the device must also be able to publish messages to the service. This means that the device needs to run both a publisher and a subscriber instance.
I’ve tried with the async API, running the two instances in two separate threads (eCos). It first seem very well, connecting success and subscribing and I’m able both send and receive message through a mosquito broker. But sadly I’ve found that the API isn’t thread safe. The socket.c module holds a list of sockets (think is called s), but this list is static and not protected so the list may be updated from one instance/thread while one other is accessing it.- A race condition causing the a zero pointer to be accessed.
Am I abusing the library by threading two instances in simultaneously or am I just doing it wrong? I guess I could transfer to the sync API, but I thought that the async API will perform better yield-wise.
Thanks in advance.
Back to the top