Ask Your Question
0

Does a callback complete before being called again?

asked 2015-12-08 06:26:49 -0600

Jay4Ros gravatar image

Hi!

Suppose I have a subscriber with a callback C. C manipulates a number of global variables and then calls a second method M, that builds a message from those global variables and publishes the message.

I am now wondering: Is is possible that C and M interfere, i.e., that M uses global variables that have been modified by a different call to C? Or, stated differently, is it possible to call C before the previous call to C has returned?

I was not able to figure out if ros::getGlobalCallbackQueue()->callAvailable blocks till completion. If interference in this situation can happen, how does one usually deal with it?

Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-12-08 06:58:24 -0600

gvdhoorn gravatar image

Callback execution is single-threaded, unless you setup things differently, by using a Multithreaded or Asynchronous spinner fi. See also roscpp/Overview/Callbacks and Spinning.

Btw, this has been asked (and answered) many times before. A quick search immediately turned up ROS callbacks, threads and spinning fi.

edit flag offensive delete link more

Comments

Hey! I saw the question you linked before, but I must have missed "Single thread spinner: the default one, takes the messages contained in a callback queue and process the callbacks one by one while blocking the execution of the thread that called it." Thanks!

Jay4Ros gravatar imageJay4Ros ( 2015-12-08 07:07:10 -0600 )edit

Oh, I guess if a program is single threaded a callback can only be called one by one.... My bad!

Jay4Ros gravatar imageJay4Ros ( 2015-12-08 07:07:54 -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

1 follower

Stats

Asked: 2015-12-08 06:26:49 -0600

Seen: 732 times

Last updated: Dec 08 '15