Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[IE] Avoid race condition in IAsyncInferRequest (#30438)

Tomasz Jankowski99763b1a699a
diff --git a/src/inference/src/dev/iasync_infer_request.cpp b/src/inference/src/dev/iasync_infer_request.cpp
index 349047d8189..6e42fef0d0b 100644
--- a/src/inference/src/dev/iasync_infer_request.cpp
+++ b/src/inference/src/dev/iasync_infer_request.cpp
@@ -99,6 +99,7 @@ void ov::IAsyncInferRequest::cancel() {
void ov::IAsyncInferRequest::set_callback(std::function<void(std::exception_ptr)> callback) {
check_state();
+ std::lock_guard<std::mutex> lock{m_mutex};
m_callback = std::move(callback);
}
@@ -148,11 +149,12 @@ ov::threading::Task ov::IAsyncInferRequest::make_next_stage_task(
if ((itEndStage == itNextStage) || (nullptr != currentException)) {
auto lastStageTask = [this, currentException]() mutable {
- auto promise = std::move(m_promise);
+ std::promise<void> promise;
std::function<void(std::exception_ptr)> callback;
{
std::lock_guard<std::mutex> lock{m_mutex};
m_state = InferState::IDLE;
+ promise = std::move(m_promise);
std::swap(callback, m_callback);
}
if (callback) {