Data protection in Listener callback

2 posts / 0 new
Last post
Last seen: 10 years 1 week ago
Joined: 04/06/2014
Posts: 1
Data protection in Listener callback


I am new to Connext/DDS.

My single C++ threaded app starts a topic manager with a subscriber and publisher. The subscriber has a listener which implements the on_data_available() method.

In on_data_available() I am creating internal objects with the data from the network and adding them to a std::vector, e.g. several c++ objects which represent geometrical shapes.

In the main loop of my application, I have a GUI code which reads the std::vector and draw the shapes. My app unfortunately crashes. As far as I understand this is because I am iterating the std::vector while new objects are being added to it.

I have seen the EA section in the user's manual. I got more confused after reading it. Are there any examples and general guidelines how to guard my std::vector? I need a lead to go and dig further.

Thank you!


Last seen: 5 years 8 months ago
Joined: 01/31/2011
Posts: 37

Hi Paul,

I don't think the ExclusiveArea concept will help you here.  It's meant to provide concurrency protection for RTI function calls; in your case, you're trying to protect access to a data structure that your application code is creating and managing.  You'll want to look into thread synchronization for how to protect your vector... have you looked at Boost for cross platform portability?

Also, you shouldn't call any blocking functions while in an RTI callback ( including any functions that may block on thread synchronization (e.g. a mutex or semaphore).  You're operating in the context of an internal RTI thread, and if you block the thread, you've disrupted the internal logic of the Connext libraries.  I'd suggest you look into using a WaitSet for notification and processing of new data (, and Since the WaitSet is called from one of your application threads, you're free to make whatever blocking calls you see fit.