Merge pull request #169 from ros2/multithreaded_idle_thread
Get rid of idle thread in MultiThreadedExecutor
This commit is contained in:
commit
bcbdd00212
1 changed files with 5 additions and 3 deletions
|
@ -42,15 +42,17 @@ MultiThreadedExecutor::spin()
|
||||||
}
|
}
|
||||||
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
|
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
|
size_t thread_id = 0;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> wait_lock(wait_mutex_);
|
std::lock_guard<std::mutex> wait_lock(wait_mutex_);
|
||||||
size_t thread_id = 1;
|
for (; thread_id < number_of_threads_ - 1; ++thread_id) {
|
||||||
for (size_t i = number_of_threads_; i > 0; --i) {
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
auto func = std::bind(&MultiThreadedExecutor::run, this, thread_id++);
|
auto func = std::bind(&MultiThreadedExecutor::run, this, thread_id);
|
||||||
threads.emplace_back(func);
|
threads.emplace_back(func);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run(thread_id);
|
||||||
for (auto & thread : threads) {
|
for (auto & thread : threads) {
|
||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue