C++11 is a new standard supported by VS2012, providing a convenient std::thread for concurrent programming.
Examples of Use:
#include <thread>voidThread_func (intArg1,intArg2,float*Arg3) {Arg3= (arg1*1.0)/(Arg1 +arg2); cout<<"arg1/(arg1 + arg2) ="<< Arg3 <<Endl; return;}voidMain () {//Number of Threads intThreadnum =3 //Dynamic Allocationthread*T; T=NewThread[threadnum]; //Results float*result = (float*)malloc(threadnum*sizeof(float)); for(inti =0; i < threadnum; i++) {T[i]= Thread (Thread_func, I, I, &Result[i]); } for(inti =0; i < threadnum; i++){ //T[i].detach ();//The main process is not equal to the child process running outT[i].join ();//main process, etc. } //post-processing towards result ...}
When you need to use the class member function ( myclass::thread_func ) to create a child thread, the following code is required:
T[i] = Thread (STD::MEM_FN (&myclass::thread_func), Object, args..);
If Thread_func is static, you do not have to write object. Otherwise, if the function that the main process is tuned to is also a member of that class, the incoming this refers back to itself.
Concurrent Programming: C++11 thread (Func, Args ...) Create a thread with a class member function