thread creation on dual processor machine 
Author Message
 thread creation on dual processor machine

Hi, all:

I am wondering how to know which processor the current thread is running on.
And is there a way to create a thread on a specific processor?...What's the
difference between _beginthread and CreateThread?

thanks,
-Kay



Sat, 14 Aug 2004 05:25:14 GMT  
 thread creation on dual processor machine
There's (almost) no way to know which processor the thread runs on. The
same thread can be assigned to one processor during one time slice and
to another on the next.

However, see SetThreadAffinityMask. It allows you to specify
processor(s) on which this thread is allowed to run. If you specify one
processor, you can be sure the thread always runs on this processor.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Hi, all:

> I am wondering how to know which processor the current thread is
running on.
> And is there a way to create a thread on a specific

processor?...What's the
Quote:
> difference between _beginthread and CreateThread?

> thanks,
> -Kay



Sat, 14 Aug 2004 05:33:07 GMT  
 thread creation on dual processor machine
Another detail - windows threads have "automatic affinity": each thread has
a "preferred CPU".  If, when a thread becomes ready, it's preferred CPU is
available, it will be scheduled on that CPU (regardless of what other CPUs
are also available).  Further, the preferred CPU is cycled between all CPUs
as threads are created:  The first thread will prefer CPU1, the second, CPU2
(etc up to however many CPUs there are), the n+1st thread will once again
prefer CPU1.

Naturally, if SetThreadAffinityMask has been used to disable the thread from
running on it's preferred CPU, then it won't - it'll pick the first ready
CPU that's enabled by the mask.

See also SetThreadIdealProcessor to set the preferred CPU for a thread.

-cd


Quote:
> There's (almost) no way to know which processor the thread runs on. The
> same thread can be assigned to one processor during one time slice and
> to another on the next.

> However, see SetThreadAffinityMask. It allows you to specify
> processor(s) on which this thread is allowed to run. If you specify one
> processor, you can be sure the thread always runs on this processor.
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



> > Hi, all:

> > I am wondering how to know which processor the current thread is
> running on.
> > And is there a way to create a thread on a specific
> processor?...What's the
> > difference between _beginthread and CreateThread?

> > thanks,
> > -Kay



Sat, 14 Aug 2004 07:07:35 GMT  
 thread creation on dual processor machine

Quote:
> What's the difference between _beginthread and CreateThread?

The former is supplied by the runtime and calls the latter. The latter is
supplied by Win32.

There are some functions in the C runtime, strtok(), for example that use
"static" variables. In a multithreading environment,managing access to
static variables is always an issue. You'll avoid problems in the runtime if
you use beginthread() or beginthreadex() ( my usual choice ) so that the
runtime can protect itself. You can use CreateThread() in C/C++ if you know
what you are doing, if you know understand all of threading issues in the
runtime, and if you are sure they don't apply. It's rarely worth the risk.

Regards,
Will



Wed, 18 Aug 2004 11:21:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. CCriticalSection and CSingleLock problem on dual-processor machine?

2. 2 threads using 50% of dual processor system

3. Multi-Threading in Dual Processor System

4. Thread on Dual Processor

5. Thread on Dual Processor

6. Dual Processor and Multi-thread

7. Thread on Dual Processor

8. Dual-processor and multi-threading

9. Dual Processor Code problem

10. VC & dual processor

11. dual processors and access violation

12. Dual processor programming

 

 
Powered by phpBB® Forum Software