You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Continuing the question from this thread: #2077
Could you please dive a little deeper into why it is unsafe for multi-threading?
Also what would be your recommended workaround for my scenario? Should I implement locks on the MQTT clients or could you point me to a thread-safe MQTT client? Basically I want to implement a MQTT client cache so I don't need to repeatedly connect and disconnect an MQTT client. But this cache will be shared by multiple threads, meaning it's likely those threads could use the same MQTT client to publish messages simultaneously.
You must synchronize the access to the MQTT client. There are different ways of doing this. One solution is to use a semaphore (SemaphoreSlim) to ensure that only a single thread is accessing the client. Another way is to start a worker thread which will process pending items from a queue and sends them. The other threads will only add items to that queue (also requires synchronization).
Describe your question
Continuing the question from this thread: #2077
Could you please dive a little deeper into why it is unsafe for multi-threading?
Also what would be your recommended workaround for my scenario? Should I implement locks on the MQTT clients or could you point me to a thread-safe MQTT client? Basically I want to implement a MQTT client cache so I don't need to repeatedly connect and disconnect an MQTT client. But this cache will be shared by multiple threads, meaning it's likely those threads could use the same MQTT client to publish messages simultaneously.
@chkr1011
Which project is your question related to?
The text was updated successfully, but these errors were encountered: