The C++11 standard supports concurrency, which includes features such as thread management, shared resource protection, inter-thread synchronization operations, and underlying atomic operations. Let's start with a simple example of how the C++11 standard multithreaded program is.
#include <iostream> #include <thread>//refers to the header file of the class that manages the thread using namespace std;//the entry function of the thread, the program prints in the newly created thread logvoid Hello () {cout << "Hello Concurrent World" << Endl;} int _tmain (int argc, _tchar* argv[]) {//Construct thread object T, set function Hello for its entry function, thread t (hello);//thread t is created, the main thread continues execution, and the child thread is added to the main thread. The main thread will then wait for the child thread to end//otherwise, the main thread may exit T.join () before the child thread ends; return 0;}
Program execution Results:
[c++11 concurrent programming] 01-hello World