Posted on May 9, 2012 by Paul

we’ve seen that C++11 allows us to use a clean syntax (compared with the one used by POSIX) for managing multithread applications. The second tutorial presents an example of threads synchronization using mutex and atomic operations. In this tutorial I’m going to show you how to use a member function and lambda with threads.

We’ll start with a simple example of a C++11 thread with a member function:

The above codes can be compiled with gcc-4.7 on Linux and Mac or with Visual Studio 11 on Windows. You can also use Clang for Mac and Linux for compiling the first example, currently Clang can’t compile anonymous functions:

Disclaimer:All data and information provided on this site is for informational purposes only. solarianprogrammer.com makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis. solarianprogrammer.com does not collect any personal information about its visitors except that which they provide voluntarily when leaving comments. This information will never be disclosed to any third party for any purpose. Some of the links contained within this site have my referral id, which provides me with a small commission for each sale. Thank you for understanding.