记一次死锁
void UpdateIPAddrs() {
proto::ServerReq req;
proto::ServerRes res;
while (!stop_) {
grpc::ClientContext context;
FillReq(&req);
if (!DoRpc(req, &res)) {
LOG(ERROR) << "Grpc error";
} else {
LOG(INFO) << "UpdateIPAddrs success";
}
std::unique_lock<std::mutex> locker(mu_);
cv_.wait_for(locker, std::chrono::seconds(5), [this] { return stop_; });
}
thread_exists_ = true;
LOG(INFO) << "UpdateIPAddrs exist";
}
void Shutdown() {
stop_ = true;
cv_.notify_all();
}
void Start() {
auto task = std::bind(&GrpcClient::UpdateIPAddrs, this);
util::ThreadPool::Instance()->Post(task);
}
void Await() {
{
std::unique_lock<std::mutex> locker(mu_);
cv_.wait(locker, [this] { return stop_; });
}
while (!thread_exists_) {
cv_.notify_all();
util::Util::Sleep(200);
}
}