From 86aae0f5a5c1c08acab2d5921a4d4b025c439c0b Mon Sep 17 00:00:00 2001 From: Matija Kecman Date: Fri, 13 Mar 2026 04:54:17 -0700 Subject: [PATCH] Use user::ThreadPool for actuator lengthrange calculation in addition to mesh and texture compilation PiperOrigin-RevId: 883099169 Change-Id: Id6832c2ca0b8f45e2f428615ae54df4b8bb6f434 --- src/user/user_model.cc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/user/user_model.cc b/src/user/user_model.cc index 7a429536..efac3b8e 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -2510,17 +2510,12 @@ void mjCModel::LengthRange(mjModel* m, mjData* data) { err[i][0] = 0; } - // launch threads - std::vector th; - th.reserve(nthread); + // launch threads and wait for them to finish + mujoco::user::ThreadPool pool(nthread); for (int i=0; i < nthread; i++) { - th.emplace_back(LRfunc, &arg[i]); - } - - // wait for threads to finish - for (int i=0; i < nthread; i++) { - th[i].join(); + pool.Schedule([&arg, i]() { LRfunc(&arg[i]); }); } + pool.WaitCount(nthread); // free mjData allocated here for (int i=1; i < nthread; i++) {