[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:
@@ -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;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user