Process and Thread Function ...


SetThreadIdealProcessor Function

Sets a preferred processor for a thread. The system schedules threads on their preferred processors whenever possible.

On a system with more than 64 processors, this function sets the preferred processor to a logical processor in the processor group to which the calling thread is assigned. Use the SetThreadIdealProcessorEx function to specify a processor group and preferred processor.

Syntax

C++
DWORD WINAPI SetThreadIdealProcessor(
  __in  HANDLE hThread,
  __in  DWORD dwIdealProcessor
);

Parameters

hThread [in]

A handle to the thread whose preferred processor is to be set. The handle must have the THREAD_SET_INFORMATION access right. For more information, see Thread Security and Access Rights.

dwIdealProcessor [in]

The number of the preferred processor for the thread. This value is zero-based. If this parameter is MAXIMUM_PROCESSORS, the function returns the current ideal processor without changing it.

Return Value

If the function succeeds, the return value is the previous preferred processor.

If the function fails, the return value is (DWORD) – 1. To get extended error information, call GetLastError.

Remarks

You can use the GetSystemInfo function to determine the number of processors on the computer. You can also use the GetProcessAffinityMask function to check the processors on which the thread is allowed to run. Note that GetProcessAffinityMask returns a bit mask whereas SetThreadIdealProcessor uses an integer value to represent the processor.

To compile an application that uses this function, define _WIN32_WINNT as 0x0400 or later. For more information, see Using the Windows Headers.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See Also

GetProcessAffinityMask
GetSystemInfo
Multiple Processors
OpenThread
Process and Thread Functions
SetThreadAffinityMask
SetThreadIdealProcessorEx
Threads

Send comments about this topic to Microsoft

Build date: 11/19/2009

Tags :


Community Content

dmex
vb.net syntax
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> Public Shared Function SetThreadIdealProcessor(ByVal handle As SafeThreadHandle, ByVal processor As Integer) As Integer
End Function
Tags :

dmex
C# syntax
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int SetThreadIdealProcessor(SafeThreadHandle handle, int processor);
Tags :

Page view tracker