robotology / gz-sim-yarp-plugins

YARP plugins for Modern Gazebo (gz-sim).
BSD 3-Clause "New" or "Revised" License
8 stars 0 forks source link

Avoid race conditions in ControlBoardDriver #102

Open xela-95 opened 4 months ago

xela-95 commented 4 months ago

Many methods that ControlBoardDriver class implements have different overloads:

While for the first case the methods have a lock_guard to guarantee a safe access to control board data, the other two typically have not that, because in principle they call the method version for the single joint for every robot joint. However In many of these methods there still some control board data members are accessed without a lock, potentially causing race conditions.

An example is: https://github.com/robotology/gz-sim-yarp-plugins/blob/13aa1987a54229aa953c2061d68a66c1d4cb7c26/plugins/controlboard/src/ControlBoardDriver.cpp#L86-L103

in which m_controlBoardData->joints.size() is called.

A way to avoid this is to switch to recursive mutex objects, so that the same mutex can be locked multiple times by nested functions.