The final parts of my video lecture series introducing the Standard Template Library are now available. Part 9 covers a single function, std::move(), and explains how rvalue references power move semantics. Part 10 covers <type_traits>, a header added by TR1/C++0x, and explains the basics of template metaprogramming.
Here's the full series:
Part 1 (sequence containers)
Part 2 (associative containers)
Part 3 (smart pointers)
Part 4 (Nurikabe solver) - see Wikipedia's article and my updated source code
Part 5 (Nurikabe solver, continued)
Part 6 (algorithms and functors)
Part 7 (algorithms and functors, continued)
Part 8 (regular expressions)
Part 9 (rvalue references)
Part 10 (type traits)
Thanks for watching.
Stephan T. Lavavej
Visual C++ Libraries Developer
Hey Stephan thanks so much for these series, I am on episode 4.
Is it possible for you to post some tips on multithreading and STL?
It is driving me absolutely mad as a student programmer.
I am using C++0x std::thread as implemented by the just thread company.
How do you personally deal with deadlocks when 2 threads have to interact with
a particular STL container?
Every new C++ developer should definitely watch this series, it is really a great introduction to the STL! Thank you Stephan!
I know this is out of topic but it would be great to get a similar video series about ATL which is an awesome and beautifully written library.
meowzorr: I'm not a multithreading expert, but I do know some things.
STL containers provide the "usual thread safety guarantee" (simultaneous reads of a single object are okay, simultaneous read/writes of different objects are okay). Therefore, although it sounds silly, the way to avoid deadlocks with STL containers is the same as the way to avoid deadlocks with everything else.
If you have multiple threads read/writing an STL container (99 readers and 1 writer qualify), all accesses (both reads and writes) to that container must be protected by a lock. That'll prevent you from mangling the container's state.
If you have to acquire multiple locks, doing so in an arbitrary order presents a well-known problem - if Thread 1 acquires Locks A and then B, and Thread 2 acquires Locks B and then A, they can become deadlocked, each holding a lock that the other wants. One method to avoid this is to define an ordering - if you always acquire Lock A before Lock B, then this can't happen. There are many other issues with locks, of which this is only the beginning.
It may be appropriate to use a container dedicated to multithreading. See my BoostCon 2009 presentation about the Parallel Patterns Library in VC10 at www.boostcon.com/.../ppl.pdf which introduces concurrent_vector and concurrent_queue. These are lock-free data structures (anything lock-free is incredibly tricky to implement; don't try this at home) that resemble their STL counterparts with some important differences.
Mark: You're welcome!
I know virtually nothing about ATL, but the popularity of this series (which began as an experiment, just as my advanced series will be an experiment) has definitely attracted the attention of the right people in the VC team (like our new Community PM, Diego). Keep asking for what you'd like to see, and hopefully they'll round up some presenters. :->
Hey thanks for reply. I had a look at the ppl, it seems like what its what I need.
Just one question, It doesnt seem to have erase method.
How am I supposed to remove an element?
erase() wouldn't be concurrency-safe. I'm not sure why it isn't provided (clear() also isn't concurrency-safe, but is provided).
Hello Stephan! I enjoy your books and speeches very much! As I am not a native speaker of English, I feel regretful not able to understand every single word in you video,so I wonder if caption can be provided and then we can better understand the details of your excellent speeched!
+1 for Mark's request for an ATL (/WTL) series, and congrats Stephan for the great job on the STL lessons!
Thanks Stephan. Those were the best videos I've ever seen. It was even better than Sysinternals.
What is your next plan? Do you have a plan which makes another lecture.
Thanks Stephan! I have been programming in the STL on and off now, but have needed a refresher and I find your lectures quite engaging and highly informative!
Also +10 for a series on the ATL!! Who should we email regarding that?