ros2-realtime-examples
ros2-realtime-examples copied to clipboard
Add minimal data sharing
This PR adds a first implemetation of the minimal_data_sharing package to show how to share data between threads in a real-time safe way.
Currently, there are some examples showing how to use std::atomics and the iceoyx library lock-free queue. I'm considering adding additional examples with more strategies:
- exchange buffer
- try-lock
- timed mutex => probably not a good idea
- mutexes with priority inheritance attributes enabled
The examples should be representative of typical use cases in ros2 code. For example, shared data set from parameters, sharing data to publish from non a non real-time context, etc
FYI @MatthiasKillat
Reposting my comment here.
I'm considering removing the minimal_atomic_message.cpp example for two reasons:
- The example is probably not a good case. I would rather use a more complex message type with more fields and show how to update the whole message atomically.
- One of the conclusions for this package should be: don't create your own lock-free algorithms. It's better to rely upon widely used libraries and well-tested code because is very error-prone. This example might send the wrong message (no pun intended).