[IE Samples] Fixed hanging of samples if InferImpl() throws exception (#11075)

* [IE Samples] Fixed hanging of samples if InferImpl() throws exception

* improved re-throw an exception
This commit is contained in:
Maxim Gordeev
2022-03-21 19:30:30 +03:00
committed by GitHub
parent 2f0620600f
commit 3ac6e95ead

View File

@@ -166,11 +166,14 @@ int main(int argc, char* argv[]) {
size_t cur_iteration = 0;
std::condition_variable condVar;
std::mutex mutex;
std::exception_ptr exception_var;
// -------- Step 10. Do asynchronous inference --------
infer_request.set_callback([&](std::exception_ptr ex) {
if (ex)
throw ex;
if (ex) {
exception_var = ex;
condVar.notify_all();
return;
}
std::lock_guard<std::mutex> l(mutex);
cur_iteration++;
@@ -193,6 +196,10 @@ int main(int argc, char* argv[]) {
// Wait all iterations of the async request
std::unique_lock<std::mutex> lock(mutex);
condVar.wait(lock, [&] {
if (exception_var) {
std::rethrow_exception(exception_var);
}
return cur_iteration == num_iterations;
});