Multiple threads publishing on the same topic

2 posts / 0 new
Last post
Last seen: 2 years 4 months ago
Joined: 12/07/2016
Posts: 10
Multiple threads publishing on the same topic


I'm developing a multithreaded application which publishes data on a DDS topic using write. My questions about this method are this:

  1. can my threads publish data using write concurently? All the publishing done on the same topic.
  2. Will the DDS library be able to perform synchronization?
  3. How long will it take, approximately, to execute this method, or will it block?
  4. What will happen with the data? Will it come out as written or will DDS overload the different samples?

If there is an example, it would be useful.

Thank you.

Gerardo Pardo's picture
Last seen: 2 months 1 week ago
Joined: 06/02/2010
Posts: 598


Most of the calls on DDS API are thread safe. Meaning they can be called concurrntly from multiple application threads and the core DDS libraries taks care of any needed synchronization so that it operates correctly. The "thread safety" of each API normally documented as part of the operation/function, look for the MT-Safety: heading (MT stands for Multi-Thread). For example this is what the C++ documentation on the FooDataWriter:write() operation says:

MT Safety:
It is UNSAFE to modify instance_data before the operation has finished. The operation is otherwise SAFE.

What this is saying is that you can safely call it from multiple threads. However you are not allowed to change the instance_data from one thread while another thread is in the write() operation for that same data.  This is an unavoidable contraint becasue the write() needs to access the instance_data in order to copy the values into the DataWriter cache.