SMP Sample
This program spawns three threads in a suspended state and assigns a processor, in round-robin sequence, to run each thread. Each thread kicks off and starts a unique statement for each iteration and continues until the first thread signals completion. Upon completion, the main thread shuts down all the threads, commences cleanup, and shuts down the program.
Source Files
| File | Description |
|---|---|
|
|
The main source code for this sample. |
Building the Sample
You can compile this sample as either an .EXE or .RTSS configuration.
Running the Sample
You must have two or more cores assigned to wRTOS or Windows in order for this sample to demonstrate the use of multiple cores for either side. No arguments are needed to run this sample.
Expected Results
Each thread prints out its iteration, thread ID, and assigned wRTOS processor, and then completes with a shutdown message.
Example output:
Executing iteration 00 of ThreadFunc1 having data = 01. Proc = 2
Executing iteration 00 of ThreadFunc2 having data = 02. Proc = 3
Executing iteration 00 of ThreadFunc3 having data = 03. Proc = 2
...
The first thread has finished, shutting down the rest.
Unexpected Results
The process affinity mask indicates only one processor and the program prints an error and exits with code 1.
Remarks
- Processor affinity is assigned using a round-robin bitmask approach based on available processors from GetProcessAffinityMask.
- Threads resume after the affinity is set.
- The Main thread waits for the first thread to finish (timeout 1000000 ms) then exits, closing all handles.
- Only processors allowed by the process affinity mask are used.
- The sample supports up to eight processors via the affinity bitmask logic.
APIs Referenced
|
RTAPI |
Windows-Supported |
|---|---|