Simple Data Exchange Sample
This sample demonstrates basic interprocess communication (IPC) using wRTOS real-time API objects. Specifically, it shows how multiple processes can synchronize and share data using a named event and shared memory. When the program is run for the first time, it attempts to open a named event. If the event does not exist, the program creates the event, writes a string into shared memory, and waits for a second process to signal the event. The second time the program is run, it finds the existing event and shared memory, reads the string, signals the event to notify the first instance, and exits. The first process, once signaled, also exits.
Source Files
| File | Description |
|---|---|
SimpleDataExchange.h
|
The header file. |
|
|
The main source code for this sample. |
Building the Sample
Build SimpleDataExchange.rtss or SimpleDataExchange.exe
Running the Sample
Run SimpleDataExchange.rtss and/or SimpleDataExchange.exe twice.
Expected Results
- The first run creates the event and shared memory, writes a string, and waits until the second process signals the event.
- The second run opens the existing event and shared memory, reads the string, and signals the event.
- Both exit cleanly.
Unexpected Result
The second event fails to open or be created, causing the first to wait indefinitely for a signal.
Remarks
- The shared memory segment transfers a string message between processes.
- Proper error handling ensures resources are released on failure.
- Both processes pause briefly before exiting to allow the user to read messages.
APIs Referenced
|
RTAPI |
Windows-Supported |
|---|---|