On Fri, 19 Oct 2012 11:11:02 -0700, 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).
>
>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>
The Boost stuff adds some higher level abstractions which can be
useful. It also considerably abstracts the OS's threading API, so
stuff written to Boost.Thread is portable to any system supporting
that library (which include most *nix and Windows).
No, pthreads is more-or-less the native threads interface for *nix,
and flavors of pthreads are available on a number of other systems.
The standard is only a few months old, and full implementations are
few (although recent versions of GCC are pretty close). OTOH, there's
considerable development, and I'd expect (approximately) full C++11
implementations to become common in the next couple of years. C++11
threads are largely based on Boost.Thread (with some changes and
limitations!), so conversion from that will often be reasonably
straight-forward.
Correct - threading cannot be generally implemented as (only) a
library. Doing it properly requires that the compiler, the OS, and
some other bits of the tool chain participate. And the compilers and
whatnot *do*. So if you're using pthreads under Linux, both GCC and
Linux are already involved in the process, so it's *not* just the
pthreads library.
>Note especially the second link there.
>
>So where should a newb start? Suggestions?
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.