Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Choosing processor to run thread

0 views
Skip to first unread message

Dimitris Thanos

unread,
Dec 12, 1997, 3:00:00 AM12/12/97
to

On a multi-processor NT machine, I would like
to make a program that has two threads, each one running on a different
processor. This is for obtainning max processing power...

Anyone seen a call to do this?

Any other ideas?

Thanks in advance,
Dimitris.

--
THANOS Dimitris
University of Geneva - CUI
Tel: +41 22 705.76.69
Fax: +41 22 705.77.80
E-mail: mailto://Dimitri...@cui.unige.ch
WWW: http://cuiwww.unige.ch/~thanos

Chris Hill

unread,
Dec 12, 1997, 3:00:00 AM12/12/97
to

In article <349158CA...@cui.unige.ch>, Dimitri...@cui.unige.ch
says...

>On a multi-processor NT machine, I would like
>to make a program that has two threads, each one running on a different
>processor. This is for obtainning max processing power...

SetThreadAffinityMask
or
SetProcessAffinityMask (NT 4 only, I think)

--
Chris Hill
hil...@cs.purdue.edu


Assaf Wodeslavsky

unread,
Dec 18, 1997, 3:00:00 AM12/18/97
to

The SetThreadAffinityMask function sets a processor affinity mask for a
specified thread.
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 proper subset of the process affinity mask
for the containing process of a thread. A thread is only allowed to run on
the processors its process is allowed to run on.
DWORD SetThreadAffinityMask (
HANDLE hThread, // handle to the thread of interest
DWORD dwThreadAffinityMask // a thread affinity mask
);

Parameters
hThread
A handle to the thread whose affinity mask the function sets.
Windows NT: This handle must have the THREAD_SET_INFORMATION access right
associated with it. For more information, see Thread Objects.
dwThreadAffinityMask
Windows 95: This value must be 1.
Windows NT: Specifies an affinity mask for the thread.

Return Values
If the function succeeds, the return value is nonzero.
Windows 95: The return value is 1. To succeed, hThread must be valid and
dwThreadAffinityMask must be 1.
Windows NT: 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.
See Also
GetProcessAffinityMask, SetThreadIdealProcessor


Dimitris Thanos <Dimitri...@cui.unige.ch> wrote in article
<349158CA...@cui.unige.ch>...


> On a multi-processor NT machine, I would like
> to make a program that has two threads, each one running on a different
> processor. This is for obtainning max processing power...
>

Jamie Hanrahan

unread,
Dec 18, 1997, 3:00:00 AM12/18/97
to

In article <349158CA...@cui.unige.ch>, Dimitris Thanos <Dimitri...@cui.unige.ch> writes:
> On a multi-processor NT machine, I would like
> to make a program that has two threads, each one running on a different
> processor. This is for obtainning max processing power...
>
> Anyone seen a call to do this?

Others have answered this with the relevant Win32 calls (not that this
has anything to do with NT kernel mode programming). Let me add a few
comments, however:

1. If no other threads want to run, NT will automatically schedule
your two threads on the two processors with no effort from you.

2. On the other hand, since there are often other threads that want
to run, setting the "hard affinity" of your threads with
SetThreadAffinity can create more performance problems than it solves.

3. You can set a "soft affinity" for your threads with
SetThreadIdealProcessor. This avoids the problems inherent with hard
affinity. But NT already assigns the preferred processor of each
thread in a process to the different processor on a round-robin basis
(with a random starting value for each process), again with no work on
your part.

--- Jamie Hanrahan, Kernel Mode Systems, San Diego CA
Internet: j...@cmkrnl.com (JH645) CompuServe: 74140,2055
drivers, internals, networks, applications, and training for VMS and Windows NT
NT driver FAQ, links, and other information: http://www.cmkrnl.com/

If you post a reply in news, please don't e-mail it too.

dave porter

unread,
Dec 19, 1997, 3:00:00 AM12/19/97
to

Just run two threads. If they're both runnable, and nothing more
important is runnable, then they will run on different CPUs.

The operating system has a scheduler. Let it schedule.

("There's no point in keeping a dog and doing the barking yourself")

dave
--
For email, please remove the 'w' from my address. Sorry.

Dimitris Thanos <Dimitri...@cui.unige.ch> wrote in article
<349158CA...@cui.unige.ch>...

> On a multi-processor NT machine, I would like
> to make a program that has two threads, each one running on a different
> processor. This is for obtainning max processing power...
>
> Anyone seen a call to do this?
>

> Any other ideas?


0 new messages