zoukankan      html  css  js  c++  java
  • c++ 多线程

    1.多线程初次使用:

    // thread example
    #include <iostream> 
    #include <thread>
    using namespace std;
    
    void foo()
    {
    //do stuff
    }
    
    void bar(int x)
    {
    //do stuff
    }
    
    int main()
    {
        thread first (foo); //spawn new thread that calls foo()
        thread second (bar, 0); //spawn new thread that calls bar(0)
        cout << "main, foo and bar now execute concurrently...
    ";
    
        first.join();
        second.join();
        cout << "foo and bar completed.
    ";
        return 0;
    
    }

    2.关于g++编译时候需要注意,不同g++版本可能不一样。

    g++  thread.cpp -o thread -lpthread -std=c++11

    The Safest Way to Get what you Want is to Try and Deserve What you Want.
  • 相关阅读:
    《Mysql
    《Redis
    《pt-query-digest 剖析 Mysql 慢日志》
    《Redis
    《Redis
    《Redis
    《Redis
    《Redis
    python中__new__()与__init__()的区别
    Python常见综合面试题
  • 原文地址:https://www.cnblogs.com/Shinered/p/9061824.html
Copyright © 2011-2022 走看看