Friends dont let friends use volatile for synchronization

pull/3088/head
Craig Tiller 9 years ago
parent a0461e52f3
commit 70a816807f
  1. 6
      test/cpp/end2end/streaming_throughput_test.cc

@ -104,11 +104,11 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
ServerReaderWriter<EchoResponse, EchoRequest>* stream)
GRPC_OVERRIDE {
EchoRequest request;
volatile bool should_exit = false;
std::atomic<bool> should_exit(false);
std::thread sender([stream, &should_exit]() {
EchoResponse response;
response.set_message(kLargeString);
while (!should_exit) {
while (!should_exit.load()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
stream->Write(response);
}
@ -117,7 +117,7 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
while (stream->Read(&request)) {
std::this_thread::sleep_for(std::chrono::milliseconds(3));
}
should_exit = true;
should_exit.store(true);
sender.join();
return Status::OK;
}

Loading…
Cancel
Save