1.简单记录
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <thread>
#include <unistd.h>
using namespace std;
void pthread1()
{
while(1){
cout << "aaaaaaaaaa\n";
sleep(1);
}
}
void pthread2()
{
while(1){
cout << "bbbbbbbbbbbb\n";
sleep(1);
}
}
int main(int argc, char** argv)
{
thread t1(pthread1);
thread t2(pthread2);
t1.join();
t2.join();
return 0;
}
2.对象
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <thread>
#include <unistd.h>
using namespace std;
class my_thread{
public:
my_thread()
{
thread t(bind(&my_thread::my_run, this, "zbyyy"));
t.join();
}
private:
void my_run(const char *name);
};
void my_thread::my_run(const char *name)
{
while(1){
cout << "----%s\n" << name;
sleep(1);
}
}
int main(int argc, char** argv)
{
my_thread my_t;
return 0;
}
END!