• 启动线程


    #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运行完毕后运行
    }

  • 相关阅读:
    Unique path
    *Jump Game
    Valid Palindrome
    *Reverse Words in a String
    Min Stack
    [?]*Simplify Path
    *Valid Parentheses
    *Sqrt(x)
    String to Integer (atoi)
    Add Digits
  • 原文地址:https://www.cnblogs.com/penuel/p/11461043.html
Copyright © 2020-2023  润新知