Skip to content

Commit 4b3a6be

Browse files
Copilotxipingyan
andauthored
Fix dangling reference in async lambda captures in thread_helper.hpp (#104)
* Initial plan * Fix dangling reference in thread_helper.hpp async lambda captures Co-authored-by: xipingyan <47800531+xipingyan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: xipingyan <47800531+xipingyan@users.noreply.github.com>
1 parent 0d416d5 commit 4b3a6be

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/cpp/src/module_genai/utils/thread_helper.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ namespace ov::genai::module::thread_utils {
1717
#endif
1818

1919
#ifdef ENABLE_DYNAMIC_LOAD_MODEL_WEIGHTS
20-
inline std::future<bool> load_model_weights_async(ov::CompiledModel& compiled_model) {
21-
auto load_fun = [&]() -> bool {
20+
inline std::future<bool> load_model_weights_async(ov::CompiledModel compiled_model) {
21+
auto load_fun = [compiled_model]() mutable -> bool {
2222
PROFILE(pm, "load_model_weights async");
2323
compiled_model.load_model_weights();
2424
// infer_request = compiled_model.create_infer_request();
2525
return true;
2626
};
27-
return std::async(std::launch::async, load_fun);
27+
return std::async(std::launch::async, std::move(load_fun));
2828
}
2929

30-
inline std::future<bool> release_model_weights_async(ov::CompiledModel& compiled_model, ov::InferRequest infer_request) {
31-
auto release_fun = [&]() -> bool {
30+
inline std::future<bool> release_model_weights_async(ov::CompiledModel compiled_model, ov::InferRequest infer_request) {
31+
auto release_fun = [compiled_model, infer_request]() mutable -> bool {
3232
PROFILE(pm, "release_model_weights async");
3333
infer_request = ov::InferRequest(); // reset infer request to release the reference to the model weights
3434
compiled_model.release_model_weights();
3535
return true;
3636
};
37-
return std::async(std::launch::async, release_fun);
37+
return std::async(std::launch::async, std::move(release_fun));
3838
}
3939
#endif
4040

0 commit comments

Comments
 (0)