ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Does ros::shutdown() also stop all Async spinner threads?

asked 2020-07-29 01:37:39 -0500

ashu gravatar image

This might be a very basic question but I couldn`t find an exact answer anywhere . Does the ros::shutdown() command also stop all the Async spinner threads automatically?

I have a lot of blocking functions in my main loop so I created a custom SIGINT signal to close the node as such:

void nodeShutdown(int sig)
{
    ROS_INFO("Closing socket connection ...");
    close(client);
    close(s);
    ros::shutdown();
}

This doesnt give me a chance to call stop on the spinner. It works but I`m not sure if this is safe. If there is a better way can someone point me towards it?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-08-01 06:56:55 -0500

Weasfas gravatar image

Hi @ashu,

If you take a look at the documentation it says: "[...] and will automatically stop when it is destroyed". Following the code, when you see its destructor here you will see that the spinner is stopped when is destroyed, that is the same to have a ros::shutdown() or SIGINT (Ctrl-C) signal sent since the memory will be freed automatically. And if you do not want to call ros::shutdown() you can call directly the destructor.

However to be more clear, in C++ for instance, by default, most signals cause an immediate, abnormal exit of the program but the particular thing in ROS is that ros::shutdown() is doing all the nasty work for you.

Regards.

edit flag offensive delete link more

Comments

Thank you for the clear explanation. This was very helpful.

ashu gravatar image ashu  ( 2020-08-01 08:24:08 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-07-29 01:37:39 -0500

Seen: 390 times

Last updated: Aug 01 '20