eclipse-iceoryx / iceoryx

Eclipse iceoryx™ - true zero-copy inter-process-communication
https://iceoryx.io
Apache License 2.0
1.62k stars 383 forks source link

Lost the sample with iceoryx single_process app #796

Closed phongt closed 3 years ago

phongt commented 3 years ago

Required information

Operating system: Debian 11 bullseye

Compiler version: gcc version 10.2.1 20210110 (Debian 10.2.1-6)

Observed result or behaviour: losing the last sample from single_process app

Expected result or behaviour: full samples should be rx

Conditions where it occurred / Performed steps:

elfenpiff commented 3 years ago

@phongt Thanks for the hint!

Actually this is not a problem here and we are not losing any samples. The single_process example is just sending and receiving for a duration of 2 seconds. When the time is up the publisher and subscriber while loop is exited and the example terminates. Incidentally it coincides with the receiving of the 20th sample, this means that the subscriber loop is exited before it has a chance to receive the 20th sample.

If you adjust the line 131 (std::this_thread::sleep_for(std::chrono::seconds(2));) so that the example runs infinitely you will see that everything is in order.

phongt commented 3 years ago

If you adjust the line 131 (std::this_thread::sleep_for(std::chrono::seconds(2));) so that the example runs infinitely you will see that everything is in order.

Thank you. I add the main loop and see more sending and receiving samples with this.

diff --git a/iceoryx_examples/singleprocess/single_process.cpp b/iceoryx_examples/singleprocess/single_process.cpp
index 9b8d026d..fe6a2a47 100644
--- a/iceoryx_examples/singleprocess/single_process.cpp
+++ b/iceoryx_examples/singleprocess/single_process.cpp
@@ -128,7 +128,8 @@ int main()
     std::thread publisherThread(publisher), subscriberThread(subscriber);

     // communicate for 2 seconds and then stop the example
-    std::this_thread::sleep_for(std::chrono::seconds(2));
+    while(keepRunning)
+        std::this_thread::sleep_for(std::chrono::seconds(2));
     keepRunning.store(false);

     publisherThread.join();