[English | ๆฅๆฌ่ช]
๐ Welcome to the World of Inter-Process Communication!
Shared Memory Based Handy Communication Manager is a comprehensive library collection that makes inter-process communication easy to implement. With this library, you can achieve complex communication processing with just a few lines of code.
๐ค What is Inter-Process Communication?
Understanding Through Familiar Examples
Inter-process communication means different programs exchanging information with each other.
๐ฑ Smartphone Example
โโโโโโโโโโโโโโโโโโโ Data โโโโโโโโโโโโโโโโโโโ
โ Camera App โ โโโโโโโโโโโโโถ โ Photo Edit App โ
โ (Capture Data) โ โ (Processing) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
๐ญ Factory Example
โโโโโโโโโโโโโโโโโโโ Sensor Data โโโโโโโโโโโโโโโโโโโ
โ Sensor Monitor โ โโโโโโโโโโโโโถ โ Control System โ
โ Program โ โ Program โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
Why is Inter-Process Communication Necessary?
๐น Efficiency Through Division of Labor
- Each program focuses on specialized processing
- Development, maintenance, and testing become easier
๐น Improved Stability
- One program crashing doesn't affect others
- Partial updates and restarts are possible
๐น Scalability
- Adjust number of processes according to processing capacity
- Distributed processing across multiple computers
๐ง Problems This Library Solves
Traditional Challenges
void* shared_mem = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
int* data = reinterpret_cast<int*>(shared_mem);
pthread_mutex_lock(&mutex);
*data = 42;
pthread_mutex_unlock(&mutex);
munmap(shared_mem, size);
Our Library's Solution
Publisher<int> pub("my_topic");
pub.publish(42);
๐ Features of Three Communication Methods
Use Case: Real-time communication within the same PC
Library | Features | Applications |
shm_pub_sub | ๐ก Publisher/Subscriber model
โก Microsecond-level ultra-low latency | Robot control, real-time image processing |
shm_service | ๐ค Request/Response model
๐ Guaranteed send/receive reliability | Database operations, file processing |
shm_action | โก Asynchronous processing model
๐ Progress monitoring & cancel functionality | Long computations, file downloads |
Publisher<SensorData> sensor_pub("robot_sensors");
sensor_pub.publish(sensor_reading);
๐ฏ Which Communication Method Should You Choose?
๐ Communication Method Selection Flowchart
What is your use case?
โ
โโ Need maximum speed (microseconds)
โ โโ ๐ก shm_pub_sub (Pub/Sub)
โ
โโ Want reliable data send/receive
โ โโ ๐ค shm_service (Service)
โ
โโ Want to monitor time-consuming processes
โโ โก shm_action (Action)
๐ Detailed Comparison Table
Feature | shm_pub_sub | shm_service | shm_action |
Communication Range | Same PC | Same PC | Same PC |
Speed | โกโกโก Fastest | โกโก Fast | โกโก Fast |
Reliability | ๐ฆ Best Effort | ๐ Guaranteed | ๐ Guaranteed |
Communication Pattern | 1:N (Broadcast) | 1:1 (Request-Response) | 1:1 (Asynchronous) |
Data Size | Any | Any | Any |
Setup Simplicity | ๐ข Very Easy | ๐ข Very Easy | ๐ก Easy |
๐ ๏ธ Development History and Design Philosophy
๐๏ธ Library Lineage
This library is based on a C library created by Professor Koichi Ozaki for robot development in his laboratory.
Evolution Process:
๐ฐ๏ธ Initial version (C language)
โ Feature additions and improvements
๐ง C++ version (Object-oriented)
๐ฏ Design Philosophy
1. ๐๏ธ Simple API
Publisher<int> pub("topic");
pub.publish(42);
2. ๐ Safety
- Type-safe template design
- Automatic memory management
- Proper error handling through exceptions
3. ๐ Performance
- Zero-copy design (shared memory)
- Efficient data structures (ring buffers)
- Minimal overhead
4. ๐ง Extensibility and Compatibility
- ROS-compatible API: Intuitive design based on ROS concepts
- Custom data types: Support for arbitrary C++ structures
- Python bindings: Same API for C++ and Python
- Platform support: Linux, Windows (WSL) support
- Compiler support: GCC, Clang, MSVC support
๐ API Design Features
Organization by Namespaces
namespace irlab::shm {
Publisher<T>, Subscriber<T>
ServiceClient<T>, ServiceServer<T>
ActionClient<T>, ActionServer<T>
}
namespace irlab::shm_base {
}
Consistent Design Patterns
๐น Sender side: Naming pattern for data senders
Publisher
(publishes data)
ServiceClient
(requests service)
ActionClient
(delegates action)
๐น Receiver side: Naming pattern for data receivers
Subscriber
(subscribes to data)
ServiceServer
(provides service)
ActionServer
(executes action)
Automatic Resource Management
{
Publisher<int> pub("topic");
pub.publish(42);
}
๐ Referenced Systems
1. fuRom [1]
- Low-latency communication through shared memory
- Efficient ring buffer implementation
2. ROS (Robot Operating System) [2]
- Communication patterns of Pub/Sub, Service, Action
- Topic-based namespace management
3. Modern C++ Design
- Resource management through RAII
- Type safety through templates
- Proper error handling through exceptions
๐ Next Steps
Do you understand the basic concepts? Now let's get hands-on experience!
๐ For Those Who Want to Try Right Now
๐ For Those Who Want to Learn Thoroughly
๐ง For Those Who Want to Know Specific Features
๐ For Python Developers
๐ References
[1] Irie, Kiyoshi. "ROS ใจใฎ็ธไบ้็จๆงใซ้
ๆ
ฎใใๅ
ฑๆใกใขใชใซใใไฝ้
ๅปถใใญใปใน้้ไฟกใใฌใผใ ใฏใผใฏ." ็ฌฌ 35 ๅๆฅๆฌใญใใใๅญฆไผๅญฆ่ก่ฌๆผไผไบ็จฟ้, RSJ2017AC2B2-01 (2017). https://furo.org/irie/papers/rsj2017_irie.pdf
[2] Open Robotics, "ROS.org", http://wiki.ros.org/
Are you ready? Let's master inter-process communication! ๐โจ