Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 3952473

Browse files
dorezyukDima Dorezyuk
andauthored
Fix deadlock when starting map with map-update-frequency set to zero (#1072)
Co-authored-by: Dima Dorezyuk <dorezyuk@magazino.eu>
1 parent 95dd23d commit 3952473

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

costmap_2d/src/costmap_2d_ros.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ void Costmap2DROS::reconfigureCB(costmap_2d::Costmap2DConfig &config, uint32_t l
326326
map_update_thread_shutdown_ = true;
327327
map_update_thread_->join();
328328
delete map_update_thread_;
329+
map_update_thread_ = NULL;
329330
}
330331
map_update_thread_shutdown_ = false;
331332
double map_update_frequency = config.update_frequency;
@@ -359,7 +360,9 @@ void Costmap2DROS::reconfigureCB(costmap_2d::Costmap2DConfig &config, uint32_t l
359360

360361
old_config_ = config;
361362

362-
map_update_thread_ = new boost::thread(boost::bind(&Costmap2DROS::mapUpdateLoop, this, map_update_frequency));
363+
// only construct the thread if the frequency is positive
364+
if(map_update_frequency > 0.0)
365+
map_update_thread_ = new boost::thread(boost::bind(&Costmap2DROS::mapUpdateLoop, this, map_update_frequency));
363366
}
364367

365368
void Costmap2DROS::readFootprintFromConfig(const costmap_2d::Costmap2DConfig &new_config,
@@ -435,10 +438,6 @@ void Costmap2DROS::movementCB(const ros::TimerEvent &event)
435438

436439
void Costmap2DROS::mapUpdateLoop(double frequency)
437440
{
438-
// the user might not want to run the loop every cycle
439-
if (frequency == 0.0)
440-
return;
441-
442441
ros::NodeHandle nh;
443442
ros::Rate r(frequency);
444443
while (nh.ok() && !map_update_thread_shutdown_)
@@ -522,8 +521,9 @@ void Costmap2DROS::start()
522521
stop_updates_ = false;
523522

524523
// block until the costmap is re-initialized.. meaning one update cycle has run
524+
// note: this does not hold, if the user has disabled map-updates allgother
525525
ros::Rate r(100.0);
526-
while (ros::ok() && !initialized_)
526+
while (ros::ok() && !initialized_ && map_update_thread_)
527527
r.sleep();
528528
}
529529

0 commit comments

Comments
 (0)