zoukankan      html  css  js  c++  java
  • install and use boost::thread

    I am describing how to use boost::thread libaray below.

    step1. download boost from http://www.boost.org/ , e.g. boost_1_52_0.tar.gz

    step2. extract the file boost_1_52_0.tar.gz to boost_1_52_0

    step3. cd to the boost file, boost_1_52_0, and exectute sh bootstrap.sh --prefix=$HOME/boost --with-libraries=thread

    step4.  run ./b2 to generate the libaries of boost thread

    step5. run ./b2 install, so .hpp and libs are in $HOME/boost.

    torstan: ls $HOME/boost
    include lib

    ---------------------

    Here is a sample code in boost_1_52_0/libs/thread/tutorial.


    #include <boost/thread/thread.hpp>
    #include <iostream>

    class factorial
    {
    public:
    factorial(int x, int& res) : x(x), res(res) { }
    void operator()() { res = calculate(x); }
    int result() const { return res; }

    private:
    int calculate(int x) { return x <= 1 ? 1 : x * calculate(x-1); }

    private:
    int x;
    int& res;
    };

    int main()
    {
    int result;
    factorial f(5, result);
    boost::thread thrd(f);
    thrd.join();
    std::cout << "5! = " << result << std::endl;
    }

    ----------------

    all:
    g++ -c factorial.cpp -Ihttp://www.cnblogs.com/include
    g++ -o factorial factorial.o http://www.cnblogs.com/lib/libboost_system.a http://www.cnblogs.com/lib/libboost_thread.a -lpthread
    clean:
    rm factorial *.o

    ------------------

    torstan: ./factorial
    5! = 120

  • 相关阅读:
    代码重构编译---make
    clickhouse日期函数
    连续登陆天数+最大登陆天数
    clickhouse基本使用
    数组
    CK优化
    Hive查询优化~布隆过滤器使用
    Presto常见问题优化
    Presto原理解析
    几种排序说明
  • 原文地址:https://www.cnblogs.com/Torstan/p/3006077.html
Copyright © 2011-2022 走看看