From cf93199f251b709a2e4e069801dfacde1850267b Mon Sep 17 00:00:00 2001 From: GwnDaan Date: Tue, 4 Feb 2025 18:15:56 +0100 Subject: [PATCH] fix(hw): data race condition on started variable --- .../isobus/hardware_integration/can_hardware_interface.hpp | 2 +- hardware_integration/src/can_hardware_interface.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware_integration/include/isobus/hardware_integration/can_hardware_interface.hpp b/hardware_integration/include/isobus/hardware_integration/can_hardware_interface.hpp index 9b836222..e0a9b7c4 100644 --- a/hardware_integration/include/isobus/hardware_integration/can_hardware_interface.hpp +++ b/hardware_integration/include/isobus/hardware_integration/can_hardware_interface.hpp @@ -190,7 +190,7 @@ namespace isobus static std::vector> hardwareChannels; ///< A list of all CAN channel's metadata static Mutex hardwareChannelsMutex; ///< Mutex to protect `hardwareChannels` static Mutex updateMutex; ///< A mutex for the main thread - static bool started; ///< Stores if the threads have been started + static std::atomic_bool started; ///< Stores if the threads have been started }; } #endif // CAN_HARDWARE_INTERFACE_HPP diff --git a/hardware_integration/src/can_hardware_interface.cpp b/hardware_integration/src/can_hardware_interface.cpp index f01c7dda..f4e5a47a 100644 --- a/hardware_integration/src/can_hardware_interface.cpp +++ b/hardware_integration/src/can_hardware_interface.cpp @@ -31,7 +31,7 @@ namespace isobus std::vector> CANHardwareInterface::hardwareChannels; Mutex CANHardwareInterface::hardwareChannelsMutex; Mutex CANHardwareInterface::updateMutex; - bool CANHardwareInterface::started = false; + std::atomic_bool CANHardwareInterface::started = { false }; CANHardwareInterface CANHardwareInterface::SINGLETON;