Simple PingPong Sample
This program spawns two threads. The threads signal each other repeatedly for a specified length of time. When time expires, the main thread signals the threads to complete and ends the program.
Source Files
| File | Description |
|---|---|
PingPong.cpp
|
The main source file that contains the Ping and Pong thread functions. |
PingPong.h
|
The header file containing declarations of thread functions. |
Building the Sample
Build PingPong.rtss or PingPong.exe.
Running the Sample
Run with no arguments.
Expected Results
The program succeeds and displays alternating Ping! and Pong! messages on the screen. (If the program fails, it displays an error message.)
Created the ping thread...
Created the pong thread...
======================================
Ping!
Pong!
...
both threads finished closing the program
Unexpected Results
There should not be consecutive Ping! or Pong! messages.
Remarks
- This sample uses three event objects shared between the two threads: two for signaling Ping and Pong operations, and one each for indicating thread completion.
- Events are auto-reset events (non-manual reset), ensuring threads proceed in turn.
- A short sleep (100 ms) at the start of each thread prevents output messages from interleaving.
- The main thread waits indefinitely for both threads to signal completion before closing handles and exiting.
APIs Referenced
|
RTAPI |
|---|