SetProcessorAffinityForThread
- Updated2023-02-21
- 2 minute(s) read
int SetProcessorAffinityForThread (int processorPoolID, int processorIndex, int *previousProcessorPoolID, int *previousProcessorIndex);
Purpose
Configures the current thread to run on a pool of processors or on one individual processor.
Processor affinity changes take effect the next time the operating system schedules the current thread to run. You can force a thread to give up the remainder of its current timeslice by calling the Windows SDK function Sleep with a sleep duration of 0. The next time the thread executes, it reflects the new processor affinity settings.
RT This function is supported only on RT systems.
Parameters
| Input | ||||||||
| Name | Type | Description | ||||||
| processorPoolID | int | The pool of processors on which to run the thread. You must pass one of the following values:
|
||||||
| processorIndex | int | If you pass kProcessorPool_None for the processorPoolID parameter, this value specifies the zero-based index of the single processor on which the thread can run. The index must represent a valid processor on the system. You can determine the total number of processors on the system by calling CmtGetNumProcessors. If you pass any other value for the processorPoolID parameter, LabWindows/CVI ignores this value. |
||||||
| Output | ||||||||
| Name | Type | Description | ||||||
| previousProcessorPoolID | int | Returns the processor pool ID of the thread before you called this function. You can pass NULL for this parameter. | ||||||
| previousProcessorIndex | int | If the previousProcessorPoolID parameter returns kProcessorPool_None, then this parameter returns the processor index of the thread before you called this function. Otherwise this parameter returns -1. You can pass NULL for this parameter. | ||||||
Return Value
| Name | Type | Description |
| status | int | Return value indicating whether the function was successful. Unless otherwise stated, zero indicates successful execution and a negative number indicates that an error occurred. You can call the GetRTUtilErrorString function to obtain a message that describes the error. |
Additional Information
Library: Real-Time Utility Library
Include file: rtutil.h
LabWindows/CVI compatibility: LabWindows/CVI 8.5 and later
Example
Refer to realtime\SymmetricMultiprocessingRT\SymmetricMultiprocessingRT.cws for an example of using the SetProcessorAffinityForThread function.