SimpleProducerConsumer Sample
This sample demonstrates synchronization and data verification across processes and CPU cores. It builds two applications:
- The consumer application opens a memory address that is shared between the wRTOS Subsystem and Windows. The program reads the shared memory address and then sets a globally named event to report that it has completed reading the data. The program ends when a TERMINATE_EVENT is signaled.
- The producer application creates and writes to a globally named shared memory address. The program writes the shared memory address and then sets a globally named event to report it has completed writing the data. The program runs for a specified number of iterations and then sets a TERMINATE_EVENT.
Source Files
| File | Description |
|---|---|
SimpleIPCConsumer.c
|
The main source file for Consumer. |
SimpleIPCProducer.c
|
The main source file for Producer. |
SimpleIPCConsumer.h
|
The header file for Consumer. |
SimpleIPCProducer.h
|
The header file for Producer. |
ProducerConsumer.h
|
The header file shared between the two applications. |
Building the Sample
Build SimpleIPCProducer and SimpleIPCConsumer using any of the supported build configurations.
Running the Sample
- Run the producer application (SimpleIPCProducer) as either an EXE or RTSS.
- Run the consumer application (SimpleIPCConsumer) as either an EXE or RTSS.
Expected Results
- Producer:
- Displays the processor ID on startup.
- Prints completion messages for each iteration, including round-trip timing (in nanoseconds).
- Displays a shutdown message after all iterations complete.
- Consumer:
- Displays the processor ID on startup.
- Operates silently unless errors occur.
- Exits cleanly upon receiving the termination event.
Unexpected Results
- The consumer application starts before the producer application.
- The producer application fails to open shared memory and waits indefinitely.
Remarks
- Communication is performed using globally named shared memory and synchronization events.
- A SHARED_DATA_AREA structure is used for exchanging data and validating identities.
- The producer tracks round-trip timing using QueryPerformanceCounter and reports performance metrics.
- Access to shared memory is synchronized through event coordination; no mutex is used.
- The consumer continuously waits for the producer’s signal, performs a read, and responds.
APIs Referenced
|
RTAPI |
Windows-Supported |
|---|---|
|
|
|