Re: SetThreadIdealProcessor()?
On Jun 13, 4:32 pm, Vincent Fatica <vi...@blackholespam.net> wrote:
On Sun, 13 Jun 2010 23:01:19 +0100, Stephen Wolstenholme
<st...@tropheus.demon.co.uk> wrote:
|On 13 Jun 2010 12:43:54 -0400, Vincent Fatica|<vi...@blackholespam.net> =
wrote:
|
|>of SetThreadIdealProcessor(), the docs say:
|>
|>>dwIdealProcessor [in]
|>
|>>The number of the preferred processor for the thread. This value is ze=
ro-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 p=
rocessor.
|>
|>But this code (VC9, XPSP3) gives the results below it:
|>
|>>for ( INT i=0; i<10; i++ )
|>> wprintf(L"%u ", SetThreadIdealProcessor(GetCurrentThread(=
), MAXIMUM_PROCESSORS));
|>
|>1 0 3 2 1 0 3 2 1 0 [yes, they cycle]
|>
|>What's up with that?
|
|It suggests you are starting multiple threads on a four processor
|machine.
|
|I start eight threads on a two processor machine and get returns 0 1 0
|1 0 1 0 1.
It's a 4-processor machine, but I'm not starting any threads.
#include <windows.h>
#include <stdio.h>
INT wmain ( INT argc, WCHAR **argv )
{
for ( INT i=0; i<10; i++ )
wprintf(L"%u ", SetThreadIdealProcessor(G=
etCurrentThread(),
MAXIMUM_PROCESSORS));
return 0;
}
g:\projects\test\release> test.exe
0 3 2 1 0 3 2 1 0 3
--
- Vince
Windows uses a round-robin scheduling algorithm. My guess is that
each time you call this function, the thread is being re-assigned to
the next available processor. Since the scheduler works in a round-
robin fashion, you see this effect. This is my educated guess :-)
http://www.installsetupconfig.com/win32programming/threadprocesssynchroniza=
tionapis11_45.html
http://msdn.microsoft.com/en-us/library/ms685100(VS.85).aspx
Hope this helps...
Tom Handal