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

Should I use a lock on resources in a listener node with multiple callbacks?

asked 2012-11-15 11:39:04 -0600

robzz gravatar image

If I have a node which listens to multiple topics & has a callback for each topic, should I need locks/mutexes on the resources that are changed by more than one callback? My question stems from whether or not callback functions are executed in new threads--could code be concurrently executing in two different callback functions at once?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2012-11-15 21:31:10 -0600

Lorenz gravatar image

The answer depends on the number of spin loops you are running. Have a look at this page.

The short answer is: if you call spin only once in your applications, you shouldn't need to synchronize. If you have multiple spinners, synchronize.

edit flag offensive delete link more

Comments

3

...anf if it's C++ (was not clear in the original question). rospy uses one thread per callback by default.

AHornung gravatar image AHornung  ( 2012-11-16 00:39:05 -0600 )edit

I was writing my node in python. I wasn't aware of the difference in handlers between python and C++. Thanks!

robzz gravatar image robzz  ( 2013-01-20 16:14:50 -0600 )edit

Question Tools

Stats

Asked: 2012-11-15 11:39:04 -0600

Seen: 2,044 times

Last updated: Nov 15 '12