Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
 SetThreadAffinityMask Function
SetThreadAffinityMask Function

Sets a processor affinity mask for the specified thread.

Syntax

DWORD_PTR WINAPI SetThreadAffinityMask(
  __in  HANDLE hThread,
  __in  DWORD_PTR dwThreadAffinityMask
);

Parameters

hThread [in]

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

This handle must have the THREAD_SET_INFORMATION or THREAD_SET_LIMITED_INFORMATION access right and the THREAD_QUERY_INFORMATION or THREAD_QUERY_LIMITED_INFORMATION access right. For more information, see Thread Security and Access Rights.

Windows Server 2003 and Windows XP/2000:  The handle must have the THREAD_SET_INFORMATION and THREAD_QUERY_INFORMATION access rights.
dwThreadAffinityMask [in]

The affinity mask for the thread.

Return Value

If the function succeeds, the return value is the thread's previous affinity mask.

If the function fails, the return value is zero. 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. 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.

Setting an affinity mask for a process or thread can result in threads receiving less processor time, as the system is restricted from running the threads on certain processors. In most cases, it is better to let the system select an available processor.

If the new thread affinity mask does not specify the processor that is currently running the thread, the thread is rescheduled on one of the allowable processors.

Requirements

ClientRequires Windows Vista, Windows XP, or Windows 2000 Professional.
ServerRequires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
HeaderDeclared in Winbase.h; include Windows.h.
LibraryUse Kernel32.lib.
DLLRequires Kernel32.dll.

See Also

GetProcessAffinityMask
Multiple Processors
OpenThread
Process and Thread Functions
SetThreadIdealProcessor
Threads


Send comments about this topic to Microsoft

Build date: 10/9/2008

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker