File tree Expand file tree Collapse file tree
examples/cpp/request_reply Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -468,16 +468,19 @@ bool ClientApp::send_requests()
468468bool ClientApp::send_request (
469469 const CalculatorRequestType& request)
470470{
471+ // Taking the mutex here to avoid taking a reply on the on_data_available callback
472+ // coming from a very fast server who replied before the request_status_ entry was set
473+ std::lock_guard<std::mutex> lock (mtx_);
474+
471475 rtps::WriteParams wparams;
472476 ReturnCode_t ret = request_writer_->write (&request, wparams);
473477
478+ requests_status_[wparams.sample_identity ()] = false ;
479+
474480 request_reply_info (" ClientApp" ,
475481 " Request sent with ID '" << wparams.sample_identity ().sequence_number () <<
476482 " ': '" << TypeConverter::to_string (request) << " '" );
477483
478- std::lock_guard<std::mutex> lock (mtx_);
479- requests_status_[wparams.sample_identity ()] = false ;
480-
481484 return (RETCODE_OK == ret);
482485}
483486
You can’t perform that action at this time.
0 commit comments