Threads and on_data_available

2 posts / 0 new
Last post
Last seen: 10 years 3 months ago
Joined: 08/09/2012
Posts: 17
Threads and on_data_available


I'm trying to understand the receive threads in Connext. My understanding is that when data is available, a receive thread will call the DataReader listener's on_data_available method. Since there can be multiple receive threads (e.g., for different transports), does that mean multiple receive threads could call into on_data_available simultaenously? I'm wondering if I need to synchronize access to class data structures when I'm inside on_data_availble.


Gerardo Pardo's picture
Last seen: 1 month 1 week ago
Joined: 06/02/2010
Posts: 602


Yes, as you said there are multiple receive threads that could call the on_data_available callback. However all calls into DataReaderListener operations are serialized by a Mutex that is placed on the Subscriber to which the DataReader belongs. This behavior is part of the DDS specification. For this reason listener calls are guranteed to not be concurrent and it is safe to access data structures from any listener callbacks, as long as the listeners are associated with DataReaders belonging to the same Subscriber.