下载
官网:http://www.boost.org/
其他:https://sourceforge.net/projects/boost/files/boost-binaries/1.78.0/
我在第二个下载的:
下载生成:boost_1_78_0-msvc-14.2-64.exe , 运行生成如下:
安装
文件夹下的bootstrap.bat,会生成一个.exe文件,可能是bjam.exe,也有可能是b2.exe。
运行生成的bjam.exe或者b2.exe,会生成相应的文件,耗时较长:
VS配置
测试
#include <boost/thread.hpp>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
boost::mutex mutex;
boost::condition_variable_any cond;
std::vector<int> random_numbers;
void fill()
{
std::srand(static_cast<unsigned int>(std::time(0)));
for (int i = 0; i < 3; ++i)
{
boost::unique_lock<boost::mutex> lock(mutex);
random_numbers.push_back(std::rand());
cond.notify_all();
cond.wait(mutex);
}
}
void print()
{
std::size_t next_size = 1;
for (int i = 0; i < 3; ++i)
{
boost::unique_lock<boost::mutex> lock(mutex);
while (random_numbers.size() != next_size)
cond.wait(mutex);
std::cout << random_numbers.back() << std::endl;
++next_size;
cond.notify_all();
}
}
int main()
{
boost::thread t1(fill);
boost::thread t2(print);
t1.join();
t2.join();
}
到此,boost库安装完成,祝学习顺利。