SetThreadGroupAffinity function (processtopologyapi.h)
Sets the processor group affinity for the specified thread.
Syntax
BOOL SetThreadGroupAffinity(
[in] HANDLE hThread,
[in] const GROUP_AFFINITY *GroupAffinity,
[out, optional] PGROUP_AFFINITY PreviousGroupAffinity
);
Parameters
[in] hThread
A handle to the thread.
The handle must have the THREAD_SET_INFORMATION access right. For more information, see Thread Security and Access Rights.
[in] GroupAffinity
A GROUP_AFFINITY structure that specifies the processor group affinity to be used for the specified thread.
[out, optional] PreviousGroupAffinity
A pointer to a GROUP_AFFINITY structure to receive the thread's previous group affinity. This parameter can be NULL.
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, use GetLastError.
Remarks
Starting with Windows 11 and Windows Server 2022, on a system with more than 64 processors, process and thread affinities span all processors in the system, across all processor groups, by default. The SetThreadGroupAffinity function restricts a thread's affinity to the processors over the single processor group specified by the given GroupAffinity. This group will also become the thread's primary group.
To compile an application that uses this function, set _WIN32_WINNT >= 0x0601. For more information, see Using the Windows Headers.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows 7 [desktop apps only] |
Minimum supported server | Windows Server 2008 R2 [desktop apps only] |
Target Platform | Windows |
Header | processtopologyapi.h |
Library | Kernel32.lib |
DLL | Kernel32.dll |