启动线程

#include <iostream>
#include <thread>
#include <unistd.h>
void hello()
{
while(1)
{

std::cout << "hello world" << std::endl;
for(int i=0;i<999999999;i++);
}
}

void hello1()
{
while(1)
{

std::cout << "uijkl" << std::endl;
usleep(1000000);
}
}


int main()
{
std::thread t(hello);    //此时会立刻运行线程t
std::thread t1(hello1);//此时会立刻运行线程t1
for(int i=0;i<999999999;i++);
std::cout << "pppppp" << std::endl;  
t.join();
t1.join();
std::cout << "ooooooo" << std::endl;   //后面的程序要等到t和t1运行完毕后运行
}

posted @ 2019-09-04 19:11  penuel  阅读(179)  评论(0编辑  收藏  举报