Shared Memory Communication

Safe DDS provides a transport layer implementation that allows communication between DomainParticipants in the same host using shared memory, while still using UDPv4 for communication between different hosts. This transport layer is enabled by default in Safe DDS, but other transport can be configured through CMake options as described in the Build Configuration section.

Note

If you only have been provided with a binary distribution of Safe DDS, it would have been built with the shared memory transport, unless it is not supported by the target platform.

Participant configuration

In order for the transport layer to use shared memory communication, the DomainParticipant must be configured to use it. This is done by adding an entry to the DomainParticipantWireProtocolQosPolicy::extra_announced_locators QoS policy with the kind set to SHARED_MEMORY. It is recommended to use the Locator::from_shm_info helper method to create the locator for this entry, which will set the necessary information for the shared memory transport to work properly. This method takes two arguments:

  • A first argument with the machine identifier, which is a 16-byte array. This shall uniquely identify the machine and be the same for all DomainParticipants in the same host.

  • A second argument with the FIFO identifier, which is a 16-bit unsigned integer. This shall uniquely identify the FIFO used for communication between DomainParticipants in the same host and shall be different for each participant in the same host.

The following example shows how to configure a DomainParticipant to use shared memory communication:

DomainParticipantQos participant_qos{};

// Set other QoS policies as usual

// ...

// The machine_id should be unique for each machine in the system, and be the same
// for all participants in the same machine.
transport::Locator::ShmMachineID machine_id = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
// The fifo_id should be unique for each participant in the same machine.
transport::Locator::ShmID fifo_id = 1234;
// Add extra announced locator for shared memory transport
memory::container::StaticList<transport::Locator, 1> extra_announced_locators;
extra_announced_locators.add(transport::Locator::from_shm_info(machine_id, fifo_id));
participant_qos.wire_protocol_qos().extra_announced_locators = &extra_announced_locators;

Resource cleanup

After running DomainParticipants that use shared memory communication, some operating-system resources may need to be cleaned up before launching the applications again. If they are left behind, a new execution may fail because those resources already exist.

This cleanup can be performed with the safedds_shm_cleanup.sh script provided in the posix_shm_transport extra support package. It can also be done manually by removing the corresponding resources from /dev/shm and /tmp (or from /dev/shmem and /var/run on QNX).