From d2aa2db650c0a6258e49a8f121e2b81095f6b25b Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 27 Jul 2021 13:41:48 +0200 Subject: [PATCH] Wait for reader to match before sending second round of samples (#2096) Signed-off-by: Miguel Company --- examples/C++/DDS/LateJoiners/latejoiners.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/C++/DDS/LateJoiners/latejoiners.cpp b/examples/C++/DDS/LateJoiners/latejoiners.cpp index b116e424c08..777e6524630 100644 --- a/examples/C++/DDS/LateJoiners/latejoiners.cpp +++ b/examples/C++/DDS/LateJoiners/latejoiners.cpp @@ -156,6 +156,14 @@ void latejoiners() return; } + // Wait for volatile reader to match with writer, otherwise it may consider the new samples as historical + std::vector matched_writers; + while (ReturnCode_t::RETCODE_OK == myReader2->get_matched_publications(matched_writers) && + matched_writers.empty() ) + { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + //Send 20 samples std::cout << "Publishing 20 samples on the topic..." << std::endl; for (uint8_t j = 0; j < 20; j++)