Discussion:
SetThreadIdealProcessor()?
(too old to reply)
Vincent Fatica
2010-06-13 16:43:54 UTC
Permalink
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.
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?
--
- Vince
Stephen Wolstenholme
2010-06-13 22:01:19 UTC
Permalink
On 13 Jun 2010 12:43:54 -0400, Vincent Fatica
Post by Vincent Fatica
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.
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.

Steve
--
Neural Planner Software Ltd www.NPSL1.com
EasyNN-plus. Neural Networks plus. www.easynn.com
SwingNN. Forecast with Neural Networks. www.swingnn.com
JustNN. Just Neural Networks. www.justnn.com
Vincent Fatica
2010-06-13 23:28:56 UTC
Permalink
On Sun, 13 Jun 2010 23:01:19 +0100, Stephen Wolstenholme
<***@tropheus.demon.co.uk> wrote:

|On 13 Jun 2010 12:43:54 -0400, Vincent Fatica
|<***@blackholespam.net> wrote:
|
|>of SetThreadIdealProcessor(), the docs say:
|>
|>>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.
|>
|>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.

But I'm not starting any threads other than the main one.
--
- Vince
Vincent Fatica
2010-06-13 23:32:09 UTC
Permalink
On Sun, 13 Jun 2010 23:01:19 +0100, Stephen Wolstenholme
<***@tropheus.demon.co.uk> wrote:

|On 13 Jun 2010 12:43:54 -0400, Vincent Fatica
|<***@blackholespam.net> wrote:
|
|>of SetThreadIdealProcessor(), the docs say:
|>
|>>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.
|>
|>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(GetCurrentThread(),
MAXIMUM_PROCESSORS));
return 0;
}

g:\projects\test\release> test.exe
0 3 2 1 0 3 2 1 0 3
--
- Vince
Tom Handal
2010-06-15 05:54:50 UTC
Permalink
Post by Vincent Fatica
On Sun, 13 Jun 2010 23:01:19 +0100, Stephen Wolstenholme
|
|>
|>>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.
|>
|>
|>>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(GetCurrentThread(),
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/threadprocesssynchronizationapis11_45.html

http://msdn.microsoft.com/en-us/library/ms685100(VS.85).aspx

Hope this helps...

Tom Handal
Vincent Fatica
2010-06-15 07:03:33 UTC
Permalink
On Mon, 14 Jun 2010 22:54:50 -0700 (PDT), Tom Handal <***@gmail.com>
wrote:

|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/threadprocesssynchronizationapis11_45.html
|
|http://msdn.microsoft.com/en-us/library/ms685100(VS.85).aspx
|
|Hope this helps...

What would help is if SetThreadIdealProcessor() were documented accurately (or
perhaps if it did what it is claimed to do). The docs say:

"If this parameter is MAXIMUM_PROCESSORS, the function returns the current ideal
processor without changing it."

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

One of those statements is not true.
--
- Vince
Loading...