Threads example question

I'm trying to learn how to use Boost.Threads with this example: http://pastebin.ca/1472832 On Ubuntu 8.04 with Boost 1.34 I'm compiling with a makefile like this: t1: t1.o g++ t1.o /usr/lib/libboost_thread-mt.so -o t1 t1.o: t1.cpp g++ -I /usr/include/boost/ -c t1.cpp However I get very similar execution times for the single-threaded version and the one which creates two threads. What am I doing wrong? thanks, Anders W

On Wed, Jun 24, 2009 at 1:08 PM, Anders Wallin
I'm trying to learn how to use Boost.Threads with this example: http://pastebin.ca/1472832
On Ubuntu 8.04 with Boost 1.34 I'm compiling with a makefile like this: t1: t1.o g++ t1.o /usr/lib/libboost_thread-mt.so -o t1 t1.o: t1.cpp g++ -I /usr/include/boost/ -c t1.cpp
However I get very similar execution times for the single-threaded version and the one which creates two threads.
What am I doing wrong?
thanks,
Anders W _____
Do you have a multi-core machine? I'd suspect with a single core multiple threads won't help things go faster. Thanks, David

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday 24 June 2009, Anders Wallin wrote:
I'm trying to learn how to use Boost.Threads with this example: http://pastebin.ca/1472832
On Ubuntu 8.04 with Boost 1.34 I'm compiling with a makefile like this: t1: t1.o g++ t1.o /usr/lib/libboost_thread-mt.so -o t1 t1.o: t1.cpp g++ -I /usr/include/boost/ -c t1.cpp
However I get very similar execution times for the single-threaded version and the one which creates two threads.
What am I doing wrong?
boost::timer doesn't tell you the elapsed wall-time necessarily. On linux, it gives elapsed cpu time (which adds together the processing time used by all processors). -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkpCbS8ACgkQ5vihyNWuA4W72ACeIA6wtUgxD3YS+puSmOGagLM6 NDcAnje+CAnXMrF457EvBoychLuSCURK =okBQ -----END PGP SIGNATURE-----

What am I doing wrong?
boost::timer doesn't tell you the elapsed wall-time necessarily. On linux, it gives elapsed cpu time (which adds together the processing time used by all processors).
Thanks, this is it. I tried clock() from time.h and it works similarly to timer. time() from time.h seems to give me wall-time, but only with 1s resolution. here: http://pastebin.ca/1473138 With four calls to the same function, I'm now getting the speedup I was expecting: 1cpu 18s 2cpus 9s 3cpus 9s 4cpus 5s AW
participants (3)
-
Anders Wallin
-
David Doria
-
Frank Mori Hess