zoukankan      html  css  js  c++  java
  • boost thread 参数传递

    例子一

    #include <iostream>
    #include <boost/thread.hpp>
    using namespace std;
     
    void func1(const int &id)
    {
        cout<<"func1 id : "<<id<<endl;
    }
     
    void func2(const int &id)
    {
        cout<<"func2 id : "<<id<<endl;
    }
     
    void func3(const int &id)
    {
        cout<<"func3 id : "<<id<<endl;
    }
     
    //线程的参数传递
    int main()
    {
        boost::thread t1(func1, 11);
        boost::thread t2(func2, 22);
        boost::thread t3(func3, 33);
        t1.join();
        t2.join();
        t3.join();
     
        system("pause");
        return 0;
    }

    例子二

    #include <iostream>
    #include <boost/thread.hpp>
     
    using namespace std;
     
    void func1(const int &id)
    {
        cout<<"func1 id : "<<id<<endl;
    }
     
    struct MyThread
    {
        void operator()(const int &id)
        {
            cout<<"MyThread id : "<<id<<endl;
        }
     
        void func1(const int &id)
        {
            cout<<"MyThread::func1 id : "<<id<<endl;
        }
    };
     
     
    //线程参数的传递方式
    int main()
    {
        //普通函数
        boost::thread t1(func1, 11);
        t1.join();
     
        //函数对象
        MyThread myThread;
        boost::thread t2(myThread, 22);
        t2.join();
     
        //成员函数
        boost::thread t3(&MyThread::func1, myThread, 33);
        t3.join();
     
        //临时对象
        boost::thread t4(MyThread(), 44);
        t4.join();
     
        //对象引用
        boost::thread t5(boost::ref(myThread), 55);
        t5.join();
     
        system("pause");
        return 0;
    }
  • 相关阅读:
    python实现图像仿射变换 以图像缩放并平移为例讲解
    图像仿射变换之图像平移 python实现
    图解图像仿射变换
    2-Maven
    1-IDEA
    公开密钥算法-RSA算法
    公开密钥算法-背包算法
    对称密钥算法
    Java内存分配与参数传递
    Oracle怎么用(常用工具)
  • 原文地址:https://www.cnblogs.com/flyinggod/p/13069096.html
Copyright © 2011-2022 走看看