SetThreadAffinityMask

SetThreadAffinityMask sets a processor affinity mask for the specified thread.

Syntax

DWORD_PTR SetThreadAffinityMask(
    HANDLE hThread,
    DWORD_PTR dwThreadAffinityMask
);

Parameters

hThread

A handle to the thread whose affinity mask is to be set.

dwThreadAffinityMask

The affinity mask for the thread.

Return Value

The thread's previous affinity mask if the function succeeds

0 (zero) if the function fails, to get extended error information, call GetLastError.

Remarks

A thread affinity mask is a bit vector in which each bit represents the processors that a thread is allowed to run on. See Specifying a Processor Affinity Bitmask for more details.

A thread affinity mask must be a subset of the process affinity mask for the containing process of a thread. A thread can only run on the processors its process can run on.

Moving a thread is equivalent to resetting its processor affinity mask. Running threads must first be suspended before their affinity may be reset. In addition, threads that use Floating Point, MMX, AVX, or SSE registers cannot be moved. You can move the thread until the first floating point, MMX, AVX, or SSE instruction is called, after which you cannot move it.

Requirements

Minimum Supported Version RTX64 2013
Header windows.h
Library Rtx_Rtss.lib

See Also:

GetProcessAffinityMask

SetThreadIdealProcessor