diff options
author | David G. Quintas <dgq@google.com> | 2017-09-07 08:37:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-07 08:37:52 -0700 |
commit | e3f5a6961164055e3d2728d1eb5d362c57db1a3e (patch) | |
tree | db438eaa8cc0e49ed0807c5c1e9547125848b8da | |
parent | 04035de631a6a46c03ebf3e8db2102d5688dc71a (diff) | |
parent | a28cca8447f8882618566bc7fa9ef344131307f3 (diff) |
Merge pull request #12415 from dgquintas/condvars_latches_again
Condition variables are not latches, again
-rw-r--r-- | test/cpp/end2end/client_lb_end2end_test.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index b588eda84f..54408db600 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -180,16 +180,18 @@ class ClientLbEnd2endTest : public ::testing::Test { std::unique_ptr<Server> server_; MyTestServiceImpl service_; std::unique_ptr<std::thread> thread_; + bool server_ready_ = false; explicit ServerData(const grpc::string& server_host, int port = 0) { port_ = port > 0 ? port : grpc_pick_unused_port_or_die(); gpr_log(GPR_INFO, "starting server on port %d", port_); std::mutex mu; + std::unique_lock<std::mutex> lock(mu); std::condition_variable cond; thread_.reset(new std::thread( std::bind(&ServerData::Start, this, server_host, &mu, &cond))); - std::unique_lock<std::mutex> lock(mu); - cond.wait(lock); + cond.wait(lock, [this] { return server_ready_; }); + server_ready_ = false; gpr_log(GPR_INFO, "server startup complete"); } @@ -203,6 +205,7 @@ class ClientLbEnd2endTest : public ::testing::Test { builder.RegisterService(&service_); server_ = builder.BuildAndStart(); std::lock_guard<std::mutex> lock(*mu); + server_ready_ = true; cond->notify_one(); } |