Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » C Paho Api Threading Issue(paho c api thread.)
C Paho Api Threading Issue [message #1794677] Tue, 04 September 2018 19:14 Go to next message
Tom Orsi is currently offline Tom OrsiFriend
Messages: 1
Registered: September 2018
Junior Member
I have the following code using the non-async libraries/api and calling setupCallbacks(). I know you might recommend using the async library/api but we can't do that right now. So according to the documentation of

https://www.eclipse.org/paho/files/mqttdoc/MQTTClient/html/async.html
https://www.eclipse.org/paho/files/mqttdoc/MQTTClient/html/pubasync.html

I have tried to serialize access to all paho api. When I do that I seem to get a deadlock. Seems like something doesn't release my lock but ALL of my locks are in auto-guards so they release when they go out of scope.

I suspect that the publish is trying to join on a thread that is driving the delivery callback , and I don't have time now research in the source code. Worth noting, if move the lock after the publish but still lock on the shared resource A everything works but could get a race in my resource A, this is for now mitigate-able in our code.

void TokenDeliveryCallback(...)
{
lock_recursive_mutex;
// access or modify shared resource A
unlock_recursive_mutex;
}

void useThreadFunction(...)
{
lock_recursive_mutex;
publish(...);
// move lock to here an its fine.
// access or modify shared resource A
unlock_recursive_mutex;
}
Re: C Paho Api Threading Issue [message #1795289 is a reply to message #1794677] Thu, 20 September 2018 04:08 Go to previous message
Ian Craggs is currently offline Ian CraggsFriend
Messages: 83
Registered: March 2013
Member
One thing to be aware of is that the only callback in the MQTTClient library that allows other MQTTClient API calls to be made within it is the connectionLost() callback - to allow a reconnect attempt to be made within it.

The other callbacks are made on the same thread, so if you make another MQTTClient API call within one, it will deadlock. Maybe this is what you are seeing.
Previous Topic:PAHO SUBSCRIBE ERROR please help me
Next Topic:Public multiples topic to Mosquitto server using Paho C library
Goto Forum:
  


Current Time: Thu Mar 28 17:45:16 GMT 2024

Powered by FUDForum. Page generated in 0.04220 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top