SubscriberStatusCallback called in other thread/signal handler?

asked 2015-10-02 09:38:56 -0600

Dimitri Schachmann gravatar image

I noticed that many existing node implementations protect their connection callback with a mutex like that:

// Monitor whether anyone is subscribed to the output
ros::SubscriberStatusCallback connect_cb = boost::bind(&DisparityNodelet::connectCb, this);

// Make sure we don't enter connectCb() between advertising and assigning to pub_disparity_
boost::lock_guard<boost::mutex> lock(connect_mutex_);
pub_disparity_ = nh.advertise<DisparityImage>("disparity", 1, connect_cb, connect_cb);

and

// Handles (un)subscribing when clients (un)subscribe
void DisparityNodelet::connectCb()
{
  boost::lock_guard<boost::mutex> lock(connect_mutex_);
  ...
}

In http://docs.ros.org/jade/api/stereo_i...

For what I've seen so far I do not need to lock for the plain topic subscriptions, because those are processed in a singe thread.

Is SubscriberStatusCallback different in that regard? Is it called from an other thread or a signal handler?

If so could anyone point to where this is documented? I would have expected it in the roscpp NodeHandle API documentation

edit retag flag offensive close merge delete