Paho Asynchronous MQTT C Client Library
Threading

The client application runs on several threads. Processing of handshaking and maintaining the network connection is performed in the background. This API is thread safe: functions may be called by multiple application threads. Notifications of status and message reception are provided to the client application using callbacks registered with the library by the call to MQTTAsync_setCallbacks() (see MQTTAsync_messageArrived(), MQTTAsync_connectionLost() and MQTTAsync_deliveryComplete()). In addition, some functions allow success and failure callbacks to be set for individual requests, in the MQTTAsync_responseOptions structure. Applications can be written as a chain of callback functions.