There's nothing to talk about. Basic use of the C++11 thread class
#include "stdafx.h" #include <iostream> #include <thread>void Func (int n) {for (int i = 0; i < 3; ++i) Std::cou T << "func" << i << Std::endl;} void Reffunc (int& N) {for (int i = 0; i < 3; ++i) std::cout << "ref func" << i << Std::endl;} int _tmain (int argc, _tchar* argv[]) {int n = 0;std::thread t1;//No display std::thread T2 (Func, n + 1);//functions that call non-reference parameters T2.join (); STD :: Thread t3 (Reffunc, Std::ref (n));//function calling reference parameter Std::thread T4 (Std::move (T3)); T4.join (); return 0;}
The code shows several uses of the thread class. Transfer function parameters, with reference and without reference two kinds.
where T3 uses move to associate threads to T4
T3 is not associated with a thread. The move involved is seen later in this article
Shown below:
Func 0
Func 1
Func 2
Ref Func 0
Ref Func 1
Ref Func 2
Please press any key to continue ...
There is also the use of join. If the code of the join IS advanced, the information of two threads is out of order
int _tmain (int argc, _tchar* argv[]) {int n = 0;std::thread t1;//No display std::thread T2 (Func, n + 1);//function calling non-reference parameter Std::thread t 3 (Reffunc, Std::ref (n));//The function that invokes the reference parameter Std::thread t4 (Std::move (T3)); T2.join (); T4.join (); return 0;}
Shown below:
Func 0ref func 0
Func 1
Func 2
Ref Func 1
Ref Func 2
Please press any key to continue ...
C++11 multithreaded learning Note one thread base uses