Threads and on_data_available

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

Hi,

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.


Thanks

Gerardo Pardo's picture
Offline
Last seen: 3 weeks 1 day ago
Joined: 06/02/2010
Posts: 602

Hi,

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.

Gerardo