Mailbox Sample
This sample creates a thread-safe instance of a mailbox. It spawns instances of reader and writer threads which inherit the mailbox instance and begin reading and writing when able. This sample runs for 1 minute before shutting down.
- The reader threads output what is read and the number of times the particular thread has gone into the mailbox to read a message.
- The writer threads put messages into the mailbox but are otherwise silent.
Source Files
| File | Description |
|---|---|
Mailbox.cpp
|
The main source file, which contains the mailbox class and a small main function to demonstrate the mailbox in use. |
Mailbox.h
|
Contains the mailbox class declaration and any required header files |
Building the Sample
Build the sample in any of the four available configurations: Debug, Release (to build MailBox.exe) or RTSSDebug, RTSSRelease (to build MailBox.rtss).
Running the Sample
Run the compiled binary with no arguments.
Expected Results
- Multiple reader threads print messages read from the mailbox, showing thread ID, message count per thread, and message content.
- Writer threads produce no output while running.
- After 60 seconds, reader and writer threads print shutdown messages indicating they have stopped.
Remarks
- The mailbox uses a mutex object to ensure thread-safe access to the internal message queue.
- The program waits for all threads to exit before terminating for a clean shutdown.
- Due to limitations with RtWaitForMultipleObjects, the program waits on each thread handle individually.
APIs Referenced
|
RTAPI |
|---|