#include<iostream>#include<thread>#include<windows.h>voidfunc(int x){for(int i =1; i <=10; i++){printf("%d\n", x);Sleep(100);}}classA{public:voidfunc(int x){for(int i =1; i <=10; i++){printf("%d\n",2);Sleep(100);}}};intmain(){
A a;
std::thread(&A::func,&a,2).detach();// 成员函数多线程这样写
std::thread(func,1).detach();getchar();// 如果主进程结束那么子线程也会死return0;}