Threads in C++

  • Thread starter Rafael Cunha de Almeida
  • Start date
R

Rafael Cunha de Almeida

I have some experience with pthreads in C and now I feel the need to
use threads in C++. I suppose pthreads could work, but I'm sure there's
a better way. Do you have suggestions of what I should use? I have a
CPU intensive application that can be easily divided into threads, each
thread will be very busy doing calculations and, as the end result, I
expect a value out of each of the threads.
 
R

.rhavin grobert

I have some experience with pthreads in C and now I feel the need to
use threads in C++. I suppose pthreads could work, but I'm sure there's
a better way. Do you have suggestions of what I should use? I have a
CPU intensive application that can be easily divided into threads, each
thread will be very busy doing calculations and, as the end result, I
expect a value out of each of the threads.

as far as im informed, there is no platform-independent way of using
threads in c++
 
S

sanjay

as far as im informed, there is no platform-independent way of using
threads in c++

ACE - framework includes support for threads and is available for many
platforms..
 
P

Pierre Yves

I've been using pthreads and it's working well. You should have a look
to the "Advanced Linux Programming" book (available online) which has
been a great reference.

Otherwise, I've used earlier on CommonC++ libraries. You can have
platform independent threads then.

PY

..rhavin grobert previously wrote the following e-mail:
 
M

Maxim Yegorushkin

I have some experience with pthreads in C and now I feel the need to
use threads in C++. I suppose pthreads could work, but I'm sure there's
a better way. Do you have suggestions of what I should use? I have a
CPU intensive application that can be easily divided into threads, each
thread will be very busy doing calculations and, as the end result, I
expect a value out of each of the threads.

You can take a look at cross-platform Intel Threading Building Blocks.
 
B

Boogie

I have some experience with pthreads in C and now I feel the need to
use threads in C++. I suppose pthreads could work, but I'm sure there's
a better way. Do you have suggestions of what I should use? I have a
CPU intensive application that can be easily divided into threads, each
thread will be very busy doing calculations and, as the end result, I
expect a value out of each of the threads.

Maybe try boost::thread ?
I've used them and I think they're ok.

Boogie
 
M

Matt P. Dz.

as far as im informed, there is no platform-independent way of using
threads in c++

Shared memory setting:
OpenMP
http://en.wikipedia.org/wiki/OpenMP
http://www.openmp.org/
// platform-independent, supported "by default" by GCC and MS Visual
Studio Pro (and many others)

Someone also mentioned Boost.Threads -- I have no experience with this
one, but from the look at documentation & examples it looks much
lower-level than OpenMP (less abstract) and hence the code might be less
elegant/more tedious to write and maintain. YMMV, though.

Distributed memory setting:
MPI
Boost.MPI
http://www.boost.org/doc/libs/1_37_0/doc/html/mpi.html
// includes links to MPI implementations -- you'll need one

Best,

Matt
 
J

Juha Nieminen

Rafael said:
I have some experience with pthreads in C and now I feel the need to
use threads in C++. I suppose pthreads could work, but I'm sure there's
a better way. Do you have suggestions of what I should use? I have a
CPU intensive application that can be easily divided into threads, each
thread will be very busy doing calculations and, as the end result, I
expect a value out of each of the threads.

Two possibilities, both of them rather portable (assuming compiler has
support, of course):

1) The boost threads library.
2) OpenMP.
 
M

Maxim Yegorushkin

  Two possibilities, both of them rather portable (assuming compiler has
support, of course):

1) The boost threads library.

boost::threads provides a subset of pthreads, so conceptually they are
pretty much the same.

The author mentioned CPU intensive application. In this case, to make
the application scale well with the number of available CPU cores, it
will need to use platform specific calls to find out the number of
available cores to create an appropriate number of worker threads. So,
it may be a bit too low-level.
2) OpenMP.

3) Cilk++ http://www.cilk.com/multicore-products/cilk-solution-overview/
4) Threading Building Blocks http://www.threadingbuildingblocks.org/
 

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