#9900·carla

Remove unnecessary thread-creation overhead from camera ROS 2 publication path

Author: JArmandoAnayaCreated Sep 25, 2026Updated Sep 25, 2026

Setup

  • CARLA version: ue58-dev
  • Platform: Linux
  • Unreal Engine: 5.8

Describe the bug

ASensor::SendDataToClient() wraps the camera ROS 2 publication (ROS2->ProcessDataFromCamera(...)) in std::async(std::launch::async, ...), storing the result in a local std::future<void>. Per the C++ standard, the destructor of a std::future obtained from std::async(std::launch::async, ...) blocks until the associated thread finishes, and that destructor runs when the local future goes out of scope at the end of SendDataToClient(). The call is therefore already effectively synchronous from the caller's perspective, while still paying the cost of spawning a new OS thread every time a camera frame is published over ROS 2.

This work is part of #9897.

Steps to reproduce

  1. Enable ROS 2 (--ros2) and spawn a camera sensor that has ROS 2 publication enabled (enable_for_ros()).
  2. Tick the world with a client listening to the camera.
  3. Observe that each call to SendDataToClient() spawns and joins a new thread for the ROS 2 publish path, even though the call already blocks until publication completes.

Expected behavior

The camera ROS 2 publication path should publish directly on the calling thread, without spawning a thread per frame, while preserving the existing publication behavior, ordering, transforms, and serialization.

Additional context

This is not a sensor-synchronization correctness bug (the blocking destructor already prevents any dangling references to Sensor/BufferView); it is a per-frame thread-creation overhead issue.