Skip to content

Commit

Permalink
Fix bug in image clients for async op (#1489)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayv25 authored and David Goodwin committed May 27, 2020
1 parent 66251c3 commit 8827516
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/clients/c++/api_v1/examples/image_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ main(int argc, char** argv)
std::vector<std::shared_ptr<nic::InferContext::Request>> requests;
size_t image_idx = 0;
size_t done_cnt = 0;
size_t sent_cnt = 0;
bool last_request = false;
std::mutex mtx;
std::condition_variable cv;
Expand Down Expand Up @@ -746,6 +747,7 @@ main(int argc, char** argv)
exit(1);
}
}
sent_cnt++;
}

// For async, retrieve results according to the send order
Expand All @@ -754,7 +756,7 @@ main(int argc, char** argv)
{
std::unique_lock<std::mutex> lk(mtx);
cv.wait(lk, [&]() {
if (done_cnt >= image_data.size()) {
if (done_cnt >= sent_cnt) {
return true;
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ main(int argc, char** argv)
std::vector<std::vector<std::string>> result_filenames;
size_t image_idx = 0;
size_t done_cnt = 0;
size_t sent_count = 0;
bool last_request = false;
std::mutex mtx;
std::condition_variable cv;
Expand All @@ -991,7 +992,6 @@ main(int argc, char** argv)
}
}


while (!last_request) {
// Reset the input for new request.
err = input_ptr->Reset();
Expand All @@ -1018,7 +1018,7 @@ main(int argc, char** argv)

result_filenames.emplace_back(std::move(input_filenames));

options.request_id_ = std::to_string(results.size());
options.request_id_ = std::to_string(sent_count);

// Send request.
if (!async) {
Expand Down Expand Up @@ -1055,6 +1055,7 @@ main(int argc, char** argv)
exit(1);
}
}
sent_count++;
}

// For async, retrieve results according to the send order
Expand All @@ -1063,7 +1064,7 @@ main(int argc, char** argv)
{
std::unique_lock<std::mutex> lk(mtx);
cv.wait(lk, [&]() {
if (done_cnt >= image_data.size()) {
if (done_cnt >= sent_count) {
return true;
} else {
return false;
Expand Down

0 comments on commit 8827516

Please sign in to comment.