ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

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

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

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 ...");

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

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

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.


edit flag offensive delete link more


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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 286 times

Last updated: Aug 01 '20