//這是最近單的實現,能夠作到了線程跨平臺this
class CThread { public: CThread():str(""){} CThread(string s){str = s;} void start(){ thread th(&CThread::run,this); //th.join(); th.detach(); }; void run() { while (1){ cout<<str<<endl; Sleep(200); } }; private: string str; }; void test(string s) { while (1) { cout<<s<<endl; Sleep(200); } } int main() { /*thread th1(test,"m"); thread th2(test,"a"); thread th3(test,"b"); th1.join(); th2.join(); th3.join();*/ CThread ch("ch"); ch.start(); CThread ss("ss"); ss.start(); while (1); return 0; }
//上面的Thread類 若是要加入各類線程鎖,
線程