No proformance improvement using boost::thread on a Duo Core PC

L

linyanhung

I used a boost multi thread in VS 2005 on a Duo Core PC, and made a two
thread process.

The code is something like this:

#include <boost/thread/thread.hpp>

void fun1()
{
//do something
}

void fun2()
{
//do something
}


int _tmain(int argc, _TCHAR* argv[])
{

boost::thread thrd(&fun1);
boost::thread thrd2(&fun2);
thrd.join();
thrd2.join();
return 0;
}

It can run, but run on only one of the two cores. The CPU usage is 50%.
Isn't that multi-thread can improve proformance on multi-core CPU?

Any help would be appreciated.
 
P

peter koch

(e-mail address removed) skrev:
I used a boost multi thread in VS 2005 on a Duo Core PC, and made a two
thread process.

The code is something like this:

#include <boost/thread/thread.hpp>

void fun1()
{
//do something
}

void fun2()
{
//do something
}


int _tmain(int argc, _TCHAR* argv[])
{

boost::thread thrd(&fun1);
boost::thread thrd2(&fun2);
thrd.join();
thrd2.join();
return 0;
}

It can run, but run on only one of the two cores. The CPU usage is 50%.
Isn't that multi-thread can improve proformance on multi-core CPU?

If only one cpu is used and both fun1 and fun2 are doing something
measurable (that is the operations are "substantial"), there is
something wrong somewhere. One thing that could go wrong is that the
two functions depend on each other, so that when fun1 runs fun2 can not
possibly run.
My suggestion would be that you tried to perform some dummy
calculations in the functions (e.g. calculating some million
trigonometric results on local values). If only cpu is used in this
case, you should ask further in a some group related to boost
(comp.boost.users?) or one related to the operating system you use.

/Peter
 
L

linyanhung

Thank you very much!! Peter.

I found that if I used

cout<<

in these two threads, then these two threads can only run on same core.

I kick out cout, then two cores were both used.
 
L

linyanhung

Sorry, I made a big mistake.

Finally I found that even I use "cout<<" in both thread, I still can
use two cores at the same time.

But if I do so, the proformance will become so low that made me fell I
use only one core.



(e-mail address removed) ¼g¹D¡G
 
L

Leo jay

Sorry, I made a big mistake.
Finally I found that even I use "cout<<" in both thread, I still can
use two cores at the same time.

But if I do so, the proformance will become so low that made me fell I
use only one core.

of course, you can't measure performance by io operations.
do some calculations in both threads, and you will see the benefit of
duo core cpu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top