Note: All the issues described below cab be avoided by using a Waitset.
Listeners are invoked by internal threads that perform critical functions within the middleware and need to run in a timely manner (see Connext DDS Threading Model). By default, Connext DDS creates a few threads to use to receive data and only a single thread to handle periodic events.
Because of this, user applications installing Listeners should never block in a Listener callback. There are several negative consequences of blocking in a listener callback:
If the application needs to make a blocking call when data is available, or when another event occurs, the application should use a WaitSet. (see Conditions and WaitSets).
Taking application mutexes/sempahores within a Listener callback may lead to unexpected deadlock scenarios. When a Listener callback is invoked, the EA (Exclusive Area) of the Entity 'E' to which the callback applies is taken by the middleware. If the application takes an application mutex 'M' within a critical section in which the application makes DDS calls affecting 'E', this may lead to following deadlock:
The middleware thread is within the entity EA trying to acquire the mutex 'M'. At the same time, the application thread has acquired 'M' and is blocked trying to acquire the entity EA.
Avoid writing data with a DataWriter within the DataReaderListener's on_data_available() callback. If the write operation blocks because e.g. the send window is full, this will lead to a deadlock.
Do not call the DataWriter's wait_for_acknowledgments() within the DataReaderListener's on_data_available() callback. This will lead to deadlock.
© 2017 RTI