In my project, two threads will call the ClientAsyncReaderWriter::Write(), but this will cause thread-safe problem.
So I try to create two ClientAsyncReaderWriter and each of them will be responsible for one thread.
But the project ended when the second ClientAsyncReaderWriter is creating.
So I wander to know if multiple ClientAsyncReaderWriter could exist simultaneously, or is there anything wrong with my creation code? Thanks a lot!
There is the associated code
request_writer_main = client_.stub().PrepareCall(
&ctx_, "/TraceSegmentReportService/collect", &client_.completionQueue());
std::cout<<"request_writer_main is init"<<std::endl;
request_writer_main->StartCall(reinterpret_cast<void*>(&ready_main));
std::cout<<"request_writer_main is started"<<std::endl;
request_writer_run = client_.stub().PrepareCall(
&ctx_, "/TraceSegmentReportService/collect", &client_.completionQueue());
std::cout<<"request_writer_run is init"<<std::endl;
request_writer_run->StartCall(reinterpret_cast<void*>(&ready_run));
You cannot reuse context for both rpc, so you must create another one for the second. You can check it in grpc::ClientContext: