LabWindows/CVI Real-Time Module

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:

Value Description
kProcessorPool_System By default, all threads in the system are assigned to the system pool. Operating system threads are always assigned to this pool.

The operating system schedules all threads assigned to this pool to the group of processors included in the pool. The operating system automatically moves threads between processors to balance the load between the processors.

By default, the system processor pool includes all processors on the system. You can change the set of processors included in the system pool by calling ConfigureProcessorPool.

The system pool always includes the first processor in the system. The first processor in the system is unique because it processes all interrupts in the system.
kProcessorPool_None Use this pool ID to indicate that the thread should not be assigned to a pool and that you will assign this thread to a specific processor. You specify the particular processor for this thread with the processorIndex parameter.
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.