How can I make RQT GUI thread-safe?

asked 2020-09-21 20:58:01 -0600

iomh gravatar image

I have a rosnode launch a cpp file that references a .ui file. The last line of the cpp file looks something like this:

PLUGINLIB_EXPORT_CLASS(my_gui_ns::MyGui, rqt_gui_cpp::Plugin)

The node is launched like this:

<node name="rqt" pkg="rqt_gui" type="rqt_gui"
args="--perspective-file $(find my_gui)/perspective/my_gui.perspective"/>

It crashes on a regular basis due to segfaults, double pointer frees, and invalid pointer frees. Sometimes it is much more frequent than others. It is hard to reproduce. It only crashes when our robots are running, each of which publish to many topics to which my_gui is subscribed.

I believe that the cpp file runs a single thread.

My hunch is that the crashes arise as a result of interactions between my rosnode thread and some QT thread when I access the QT objects, but I cannot say this for sure.

My question is this: How can I be sure that my data accesses are thread-safe?

edit retag flag offensive close merge delete


@iomh Generally speaking to include the UI file in the cpp you do not need that last line but use the CMake to add compile tasks for the UI with the QT5_WRAP_UI() command. On the other hand, if you are not sure of what can be happening you can try debugging the program step y step and/or use GDB fo C++. The main problem when ensuring your program does not have a thread execution problem is that sometimes is very complex to check the possible interactions between variables and threads. Most of the ROS components are thread safe, the same happens with Qt5, but you may want to detect critical sections and perform some tests on these.

Weasfas gravatar image Weasfas  ( 2020-09-22 04:27:42 -0600 )edit
Dirk Thomas gravatar image Dirk Thomas  ( 2020-09-22 11:13:11 -0600 )edit