Skip to content

Commit

Permalink
Fix the locking on the policy object in cross entropy planner.
Browse files Browse the repository at this point in the history
When the policy is written, it should be done with unique_lock and not shared_lock. This mistake leads to an occasional crash.

PiperOrigin-RevId: 696471417
Change-Id: I2b54c0d87d0bb11214210624d9f042f1b7c4d413
  • Loading branch information
nimrod-gileadi authored and copybara-github committed Nov 14, 2024
1 parent 868f357 commit 80129e6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mjpc/planners/cross_entropy/planner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <algorithm>
#include <chrono>
#include <cmath>
#include <mutex>
#include <shared_mutex>

#include <absl/random/random.h>
Expand Down Expand Up @@ -267,7 +268,7 @@ void CrossEntropyPlanner::OptimizePolicy(int horizon, ThreadPool& pool) {

// update
{
const std::shared_lock<std::shared_mutex> lock(mtx_);
const std::unique_lock<std::shared_mutex> lock(mtx_);
policy.plan.Clear();
policy.plan.SetInterpolation(interpolation_);
for (int t = 0; t < num_spline_points; t++) {
Expand Down

0 comments on commit 80129e6

Please sign in to comment.