Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages
Started by Ilan Azbel
Thu, 27 Mar 2003 13:49
Threads and CPUs
Author: Ilan Azbel
Date: Thu, 27 Mar 2003 13:49
Date: Thu, 27 Mar 2003 13:49
4 lines
1007 bytes
1007 bytes
I have a multi-threaded application running on a dual-CPU computer. Is there any way to find out on which CPU a thread is running? Ilan
Re: Threads and CPUs
Author: Early Ehlinger
Date: Thu, 27 Mar 2003 21:17
Date: Thu, 27 Mar 2003 21:17
36 lines
2323 bytes
2323 bytes
"Ilan Azbel" <ilan@mdio.net> wrote:
> I have a multi-threaded application running on a dual-CPU computer. Is
there
> any way to find out on which CPU a thread is running?
This question assumes that your thread will stay on the CPU once you ask.
This is not the case (by default):
int thread_func( )
{
/* Pretend GetCurrentThreadCpuNumber() is an API
that returns the current thread cpu number at
the time the function was called. */
int cpu_num = GetCurrentThreadCpuNumber( );
/* OOPS! The OS just preempted me and moved me to
the other CPU, so the next line of output
will be a flat-out lie! */
std::cout
<< "I think I\'m running on cpu number "
<< cpu_num << std::endl;
}
Note that you /can/ force your thread to run on a specific processor via
SetThreadAffinityMask or even suggest a processor to the OS via
SetThreadIdealProcessor. But in both cases this is not likely to get you
any performance boost, because other threads can still run on that processor
and preempt your thread.
You might be able to get a tell which CPU your thread is running on by using
the CPUID assembly instruction, but it won't do you much good.
--
-- Early Ehlinger CEO, ResPower Inc - Toll-Free : 866-737-7697
-- www.respower.com -- 500+ GHz Supercomputer Starting At USD$0.50/GHz*Hour
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads