Series
Guide
apt-get
1 2
| sudo apt-get install libboost-all-dev
|
compile from source
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
tar xzvf boost_1_66_0.tar.gz cd boost_1_66_0/
sudo apt-get update sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev build-essential libbz2-dev
./bootstrap.sh --prefix=/usr/local/
./b2 --help
./b2 -j8 variant=release link=shared threading=multi runtime-link=shared sudo ./b2 -j8 install
|
thread example
thread_demo.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
#include <boost/thread.hpp> #include <boost/bind.hpp>
boost::mutex io_mutex;
void count(int id) { for (int i = 0; i < 10; i++) { boost::mutex::scoped_lock lock(io_mutex); std::cout << id << ":" << i << std::endl; } }
int main(int argc, char* argv[]) { boost::thread thrd1(boost::bind(&count, 1)); boost::thread thrd2(boost::bind(&count, 2)); thrd1.join(); thrd2.join(); return 0; }
|
CMakeLists.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| cmake_minimum_required (VERSION 2.6)
project (thread_main) enable_language(C) enable_language(CXX)
set(Boost_USE_RELEASE_LIBS ON)
set(Boost_USE_MULTITHREAD ON)
find_package(Boost 1.5.8 REQUIRED COMPONENTS serialization date_time system filesystem thread timer) include_directories(${Boost_INCLUDE_DIRS})
add_executable (thread_main thread_main.cpp )
target_link_libraries (thread_main ${Boost_LIBRARIES} )
|
thread pool
see thread pool with boost
Reference
History