Threads in C++

Discussion in 'C++' started by Rafael Cunha de Almeida, Nov 26, 2008.

  1. 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.
     
    Rafael Cunha de Almeida, Nov 26, 2008
    #1
    1. Advertising

  2. On 26 Nov., 15:03, 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.


    as far as im informed, there is no platform-independent way of using
    threads in c++
     
    .rhavin grobert, Nov 26, 2008
    #2
    1. Advertising

  3. Rafael Cunha de Almeida

    sanjay Guest

    On Nov 26, 7:36 pm, ".rhavin grobert" <> wrote:
    > On 26 Nov., 15:03, 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.

    >
    > 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..
     
    sanjay, Nov 26, 2008
    #3
  4. Rafael Cunha de Almeida

    Pierre Yves Guest

    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 <>
    > 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++
     
    Pierre Yves, Nov 26, 2008
    #4
  5. On Nov 26, 2:03 pm, 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.


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

    --
    Max
     
    Maxim Yegorushkin, Nov 26, 2008
    #5
  6. Rafael Cunha de Almeida

    Boogie Guest

    On Nov 26, 3:03 pm, 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.


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

    Boogie
     
    Boogie, Nov 26, 2008
    #6
  7. Rafael Cunha de Almeida

    Matt P. Dz. Guest

    On 11/26/2008 3:36 PM, .rhavin grobert wrote:
    > On 26 Nov., 15:03, 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.

    >
    > 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
     
    Matt P. Dz., Nov 26, 2008
    #7
  8. 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.
     
    Juha Nieminen, Nov 27, 2008
    #8
  9. On Nov 27, 10:29 pm, Juha Nieminen <> 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-products/cilk-solution-overview/
    4) Threading Building Blocks http://www.threadingbuildingblocks.org/

    --
    Max
     
    Maxim Yegorushkin, Nov 28, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Codemonkey
    Replies:
    1
    Views:
    433
    Ying-Shen Yu[MSFT]
    Oct 30, 2003
  2. yoda
    Replies:
    2
    Views:
    463
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  3. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    432
    William Ahern
    Aug 27, 2004
  4. Pedro Pinto

    Java Threads - Get running threads

    Pedro Pinto, Apr 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,483
    Arne Vajhøj
    Apr 9, 2008
  5. Une bévue
    Replies:
    0
    Views:
    176
    Une bévue
    Jun 14, 2006
Loading...

Share This Page