Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Threads in C++

Reply
Thread Tools

Threads in C++

 
 
Rafael Cunha de Almeida
Guest
Posts: n/a
 
      11-26-2008
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.
 
Reply With Quote
 
 
 
 
.rhavin grobert
Guest
Posts: n/a
 
      11-26-2008
On 26 Nov., 15:03, Rafael Cunha de Almeida <(E-Mail Removed)>
wrote:
> 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++
 
Reply With Quote
 
 
 
 
sanjay
Guest
Posts: n/a
 
      11-26-2008
On Nov 26, 7:36 pm, ".rhavin grobert" <(E-Mail Removed)> wrote:
> On 26 Nov., 15:03, Rafael Cunha de Almeida <(E-Mail Removed)>
> wrote:
>
> > 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++


ACE - framework includes support for threads and is available for many
platforms..
 
Reply With Quote
 
Pierre Yves
Guest
Posts: n/a
 
      11-26-2008
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:
> On 26 Nov., 15:03, Rafael Cunha de Almeida <(E-Mail Removed)>
> wrote:
>> 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++

 
Reply With Quote
 
Maxim Yegorushkin
Guest
Posts: n/a
 
      11-26-2008
On Nov 26, 2:03*pm, Rafael Cunha de Almeida <(E-Mail Removed)>
wrote:
> 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.

--
Max

 
Reply With Quote
 
Boogie
Guest
Posts: n/a
 
      11-26-2008
On Nov 26, 3:03*pm, Rafael Cunha de Almeida <(E-Mail Removed)>
wrote:
> 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
 
Reply With Quote
 
Matt P. Dz.
Guest
Posts: n/a
 
      11-26-2008
On 11/26/2008 3:36 PM, .rhavin grobert wrote:
> On 26 Nov., 15:03, Rafael Cunha de Almeida <(E-Mail Removed)>
> wrote:
>> 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++


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
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      11-27-2008
Rafael Cunha de Almeida wrote:
> 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.
 
Reply With Quote
 
Maxim Yegorushkin
Guest
Posts: n/a
 
      11-28-2008
On Nov 27, 10:29*pm, Juha Nieminen <(E-Mail Removed)> wrote:
> Rafael Cunha de Almeida wrote:
>
> > 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.


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-produc...tion-overview/
4) Threading Building Blocks http://www.threadingbuildingblocks.org/

--
Max
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Threads - Get running threads Pedro Pinto Java 2 04-08-2008 11:44 PM
[new to threads] threads with UI and loop Une bévue Ruby 0 06-14-2006 10:22 AM
TB View, Threads, Threads with unread The Invisible Man Firefox 1 03-20-2006 02:09 AM
Standard Threads vs Weightless Threads yoda Python 2 08-01-2005 09:12 PM
threads without threads sindica@gmail.com C Programming 4 08-27-2004 09:25 PM



Advertisments