ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
An example on how to protect callbacks with mutextes. You can use POSIX mutexes, then you have to change enter()/exit() by pthread_mutex_lock()/_unlock(). Please see that
myNode::myCallback(const my_msgs::m1::ConstPtr& msg)
{
mutex.enter();
this->a = msg->a;
mutex.exit();
}
myNode::myCallback(const my_msgs::m2::ConstPtr& msg)
{
mutex.enter();
this->b = msg->b;
mutex.exit();
}
myNode::process()
{
mutex.enter();
std::cout << this->a + this->b << std::endl;
mutex.exit();
}