Threading tutorial for C++?

M

markspace

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?
 
Ö

Öö Tiib

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.
 
J

Jorgen Grahn

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
 
P

ptyxs

Le 20/10/2012 09:31, Jorgen Grahn a écrit :
Probably the best thing to do : study the recent (C++11 compliant) book
by Anthony Williams
C++ Concurrency In Action

Ptyxs
 
L

Luca Risolia

Le 20/10/2012 09:31, Jorgen Grahn a écrit :

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.
 
M

markspace

Le 20/10/2012 09:31, Jorgen Grahn a écrit :

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.
 
M

markspace

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.
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top