A question about AsyncSpinner
Dear all,
I would like to know what would happen withros::AsyncSpinner spinner(0);
Does that mean the callback is still in the same thread as the main program?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Dear all,
I would like to know what would happen withros::AsyncSpinner spinner(0);
Does that mean the callback is still in the same thread as the main program?
According to the ros::AsyncSpinner Class Reference (from the roscpp
API docs):
ros::AsyncSpinner::AsyncSpinner(uint32_t thread_count)
Simple constructor. Uses the global callback queue.
Parameters:
thread_count: The number of threads to use. A value of 0 means to use the number of processor cores
Edit:
Then the question becomes, what would happens if I use 1?
From the source of AsyncSpinnerImpl::start()
(lines 143-167):
void AsyncSpinnerImpl::start()
{
[..]
for (uint32_t i = 0; i < thread_count_; ++i)
{
threads_.create_thread(boost::bind(&AsyncSpinnerImpl::threadFunc, this));
}
}
In this, thread_count_
is set in the ctor of AsyncSpinnerImpl
to be either equal to the nr of cpus, or to the value passed in via the ctor of AsyncSpinner
.
Does that mean the callback is still in the same thread as the main program? will the callback blocks the main loop?
If you specify a thread_count
of 1, a single additional thread is created. So no, iiuc, the callback processing should not happen in the 'main loop'.
PS: I would've found it rather odd for a class called AsyncSpinner
to return to synchronous behaviour only be changing the nr of threads it uses.
PPS: this is also partly explained in roscpp/Overview/Callbacks and Spinning - Multi-threaded Spinning on the ROS wiki.
Asked: 2015-01-27 01:15:21 -0500
Seen: 891 times
Last updated: Jan 27 '15
subscriber class method callback problem
Can AsyncSpinner spins in functions?
Understanding async spinner in ROS1
multithread can't read 2 topics
Nodes are takin 100% cpu on any computer
Async spinner with callback that is class member
Issues with multiple controller_manager instances, async spinner
How can I get status in Rviz goal_tool.cpp?
Issues with Spin() and AsyncSpinner: multithreaded application