Click here to Skip to main content
15,916,462 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

what is the best way to gain/increase ones skills in multithreaded programming? (c++).

Thank you.
Posted

Practice and in particular practice under pressure.
You can learn the theory and APIs for multithreading for fun and by experimenting but its only when you have to debug a real product that it crashing that in my experience the ideas finally set in place. Then you really get it.
As I'm sure you're aware multithreading/parallelism is the hardest thing in software to get good at.

One trick I've used is to represent the items of data in a particular problem with physical objects, apples or oranges are good. Discuss the problem with your colleagues but each person can only speak when they are holding a piece of fruit and once you've assigned each piece of fruit to a part of the problem they can only speak about that part of the problem when they're holding that piece of fruit.
They can put their peice of fruit down on the table at any time and pick up any number of pieces of fruit one at a time but only from the table.
It's a fun game to play and pretty soon you work out how to lock and unlock your data effectively and to make best use of your resources.
Sometimes it's best to have a boss who tells people what fruit to take or even hands it out and takes it back. Sometimes it's best to work cooperatively by following simple rules to avoid deadlocks when you need multiple resources.
 
Share this answer
 
Comments
Richard C Bishop 10-Apr-13 16:35pm    
Nice job, that will be very handy for the OP. +5.
Dan page 10-Apr-13 16:37pm    
ok, so far i found this material which seems Ok: http://www.codeproject.com/Articles/14746/Multithreading-Tutorial
Matthew Faithfull 10-Apr-13 16:45pm    
Looks OK at a glance, out of date with regard to C++11 though. C++ threads are supposed to be standardised from now-ish although most compilers and libraries haven't caught up yet. It's worht knowing what the standard will be though.
Sergey Alexandrovich Kryukov 10-Apr-13 17:02pm    
I'm really afraid of the possibility to understand this post wrong. "Practice" no way should be trial-and-error approach. This is the important general rule, critically important in threading. Threading problems, like deadlocks and race conditions, may not appear for millions of years, and yet this is not a good reason to consider the system "correct". This is not my fantasy: such situations are really easy to create. There is no an experimental proof; all the facts of threading behavior can only be proven theoretically. Practice and experience is just the way to devise theoretically correct solutions quickly and reliably. Even the rule-of-thumb approach can be used, but the developer should be 100% sure it's all on the safe side.

Failing code is not too bad, the "working" code which can fail tomorrow or years later is much worse. And multithreading if full of such cases. A developer has no right for a single one.

—SA
Matthew Faithfull 10-Apr-13 17:13pm    
Thanks, a great explanation of why multithreading is not just hard but the hardest thing. Anything less than 100% is no good at all.
It is called the conundrum of life:

"Experience comes from Wisdom. Wisdom comes from lack of Experience".

Go for it...
 
Share this answer
 
Comments
ayesha hassan 17-Apr-13 6:53am    
5.
Read the material, practice the material. Then, practice some more and read some more.
 
Share this answer
 
Comments
CPallini 10-Apr-13 16:29pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900