Threading tutorial for C++?

Discussion in 'C++' started by markspace, Oct 19, 2012.

  1. markspace

    markspace Guest

    Hey all, I've got a little personal project to learn a bit about
    multithreading in C++, and I was wondering if anyone would like to give
    me a few pointers (no pun intended).

    What would you recommend as a good tutorial? Threading seems to be a
    bit in flux, still, since standards have been long in coming (no flames
    please) and so I was wondering from a practical standpoint what you'd
    recommend.

    Let's assume a Unix/Linux environment. I'll tackle Windows later.

    I have a recommendation for a Boost tutorial, although the article is
    really old.

    <http://www.drdobbs.com/cpp/the-boostthreads-library/184401518>

    There's of course a lot of old pthreads tutorials. I wonder if pthreads
    has been obviated by now, however.

    <http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html>
    <http://codebase.eu/tutorial/posix-threads-c/>

    So I'm also wondering how prevalent c++11 is, in your practical opinion.

    <http://solarianprogrammer.com/2011/12/16/cpp-11-thread-tutorial/>

    What should I tackle first? Some articles I researched seem to say
    multithreading can't truly (i.e., correctly) be implemented in a
    library. So is pthreads really relevant any more?

    <http://www.hpl.hp.com/personal/Hans_Boehm/c++mm/>
    <http://www.hpl.hp.com/techreports/2004/HPL-2004-209.html>

    Note especially the second link there.

    So where should a newb start? Suggestions?
     
    markspace, Oct 19, 2012
    #1
    1. Advertising

  2. markspace

    Öö Tiib Guest

    On Friday, 19 October 2012 21:11:06 UTC+3, markspace wrote:
    > What should I tackle first? Some articles I researched seem to say
    > multithreading can't truly (i.e., correctly) be implemented in a
    > library. So is pthreads really relevant any more?


    If you want the knowledge gained to have best longevity then you should perhaps study std::thread of c++11 as first thing.

    If you want to start more narrow and more practical then take boost::asio first. It deals with one very important topic: asynchronous communication. It uses boost::thread that is somewhat similar to std::thread.
     
    Öö Tiib, Oct 19, 2012
    #2
    1. Advertising

  3. markspace

    Jorgen Grahn Guest

    On Fri, 2012-10-19, markspace wrote:
    > Hey all, I've got a little personal project to learn a bit about
    > multithreading in C++, and I was wondering if anyone would like to give
    > me a few pointers (no pun intended).


    My first advice would be to learn when *not* to use it, and instead go
    for separate processes or event multiplexing using select(2),
    non-blocking I/O and so on. Most use of threads I see in production
    code is our of ignorance and/or to hide design flaws. Most such code
    is also buggy, and works more or less by accident.

    (But I'm unusually negative. I acknowledge that there *are* valid
    uses for threads.)

    Eric Raymond: "Threads - Threat or Menace?"
    http://www.catb.org/esr/writings/taoup/html/ch07s03.html#id2923889

    ....
    > Let's assume a Unix/Linux environment. I'll tackle Windows later.


    There's a difference between that and "I'm not interested in Windows
    at all". You may have to start over when/if you look at Windows.

    ....

    > There's of course a lot of old pthreads tutorials. I wonder if pthreads
    > has been obviated by now, however.


    Pthreads are alive and well, and won't go away anytime soon. You
    could use that API, but use it in a modern way. I suspect that we've
    found better patterns for thread communication since those tutorials
    were written.

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
     
    Jorgen Grahn, Oct 20, 2012
    #3
  4. markspace

    ptyxs Guest

    Le 20/10/2012 09:31, Jorgen Grahn a écrit :
    > On Fri, 2012-10-19, markspace wrote:
    >> Hey all, I've got a little personal project to learn a bit about
    >> multithreading in C++, and I was wondering if anyone would like to give
    >> me a few pointers (no pun intended).


    Probably the best thing to do : study the recent (C++11 compliant) book
    by Anthony Williams
    C++ Concurrency In Action

    Ptyxs
     
    ptyxs, Oct 20, 2012
    #4
  5. markspace

    Luca Risolia Guest

    On 20/10/2012 15:05, ptyxs wrote:
    > Le 20/10/2012 09:31, Jorgen Grahn a écrit :
    >> On Fri, 2012-10-19, markspace wrote:
    >>> Hey all, I've got a little personal project to learn a bit about
    >>> multithreading in C++, and I was wondering if anyone would like to give
    >>> me a few pointers (no pun intended).

    >
    > Probably the best thing to do : study the recent (C++11 compliant) book
    > by Anthony Williams
    > C++ Concurrency In Action


    I agree with you. It's one of the best books about concurrency in C++
    and about concurrency in general.
     
    Luca Risolia, Oct 20, 2012
    #5
  6. markspace

    markspace Guest

    On 10/20/2012 6:05 AM, ptyxs wrote:
    > Le 20/10/2012 09:31, Jorgen Grahn a écrit :
    >> On Fri, 2012-10-19, markspace wrote:
    >>> Hey all, I've got a little personal project to learn a bit about
    >>> multithreading in C++, and I was wondering if anyone would like to give
    >>> me a few pointers (no pun intended).

    >
    > Probably the best thing to do : study the recent (C++11 compliant) book
    > by Anthony Williams
    > C++ Concurrency In Action



    Thank you! An excellent suggestion.
     
    markspace, Oct 20, 2012
    #6
  7. markspace

    markspace Guest

    On 10/19/2012 12:03 PM, Robert Wessel wrote:

    > Eh... Either pthreads or Boost.Threads, with the edge going to the
    > latter. With Boost.Threads everything will be much more C++ friendly,
    > and you have the advantages of portability, but you're a few extra
    > steps away from what's going on at the system level. You'll also find
    > more pthreads expertise in the world. Going the C++11 route is
    > probably plausible too, although you'll be a bit of an explorer at
    > this point.
    >



    Thanks to you and Oo Tiib (sorry, I can't do umlats), some good advice
    from you two.
     
    markspace, Oct 20, 2012
    #7
    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. Rensjuh
    Replies:
    7
    Views:
    1,008
    Mabden
    Sep 2, 2004
  2. Andreas Neudecker

    Tutorial/Docs on threading with Python?

    Andreas Neudecker, Jan 21, 2004, in forum: Python
    Replies:
    1
    Views:
    313
    Peter Hansen
    Jan 21, 2004
  3. Replies:
    9
    Views:
    1,077
    Mark Space
    Dec 29, 2007
  4. Steven Woody
    Replies:
    0
    Views:
    441
    Steven Woody
    Jan 9, 2009
  5. Steven Woody
    Replies:
    0
    Views:
    464
    Steven Woody
    Jan 9, 2009
Loading...

Share This Page