Boost库的使用(Windows)
来源:互联网 发布:彩票免费计划软件 编辑:程序博客网 时间:2024/06/04 15:54
1、Boost库下载
进入网页后点击download
2、解压、执行脚本
如解压到D:\boost_1_60_0,并执行bootstrap.bat文件。点击运行即可,直至控制台自动关闭。
3、编译
上一步生成b2.exe文件,点击运行既可,直至控制台自动关闭。
4、VS2015试用
A、添加环境变量
添加D:\boost_1_60_0\stage\lib到path
B、项目属性设置
D:\boost_1_60_0添加到:项目|项目属性|VC++目录|包含目录。
D:\boost_1_60_0\stage\lib添加到:项目|项目属性|配置属性|连接器|常规|附加库目录。
5、代码
#include <iostream>#include <thread>#include <map>#include <string>#include <mutex>#include <boost/thread/shared_mutex.hpp>//具体到相应文件#include <boost/thread/thread.hpp>class dns_entry { std::string s;public: dns_entry() = default;//默认构造函数 dns_entry(const std::string &_s):s(_s){} std::string get() const { return s; }};class dns_cache{ std::map<std::string, dns_entry> entries; mutable boost::shared_mutex entry_mutex;public: dns_entry find_entry(const std::string & domain) const { boost::shared_lock<boost::shared_mutex> lk(entry_mutex); // 1,保护共享和只读权限 std::cout << "共享\t" << domain << std::endl; const std::map<std::string, dns_entry>::const_iterator it = entries.find(domain); std::cout << "共享锁\t" << domain <<"释放"<< std::endl; return (it == entries.end()) ? dns_entry() : it->second; } void update_or_add_entry(const std::string & domain, const dns_entry & dns_details) { std::lock_guard<boost::shared_mutex> lk(entry_mutex); // 2,提供独占访问权限 std::cout << "独占锁......" << domain << "......" << dns_details.get() << std::endl; entries[domain] = dns_details; std::cout << "独占锁......" << domain << "......" << dns_details.get() <<"......释放"<< std::endl; }};void funA(const char &c,dns_cache &dns_c){ std::string s{ "dm" }; for (unsigned i = 0;i < 5;++i) { dns_entry ds{ "dns_d" + s }; dns_c.update_or_add_entry(s, ds); s += c; }}void funB(const char &c, const dns_cache &dns_c){ std::string s{ "dm" }; for (unsigned i = 0;i < 5;++i) { dns_entry de=dns_c.find_entry(s); s += c; }}int main(){ dns_cache dc; char c1 = 'a', c2 = 'b'; std::thread t1{ funA,std::ref(c1),std::ref(dc) }, t2{ funA,std::ref(c2),std::ref(dc) },//update t3{ funB,std::ref(c1),std::ref(dc) }, t4{ funB,std::ref(c2),std::ref(dc) };//find system("pause"); return 0;}
0 0
- Boost库的使用(Windows)
- Windows下使用Boost库的安装
- 在windows下的qcreator中使用boost库
- boost库在windows下的编译和使用
- “Windows下编译boost程序库”和“使用boost库的编译环境的设置”
- windows下的boost库
- Boost在windows上的使用
- boost库的使用
- Boost库的使用
- Windows下如何使用BOOST C++库
- windows下使用gcc编译boost库
- Windows下如何使用BOOST C++库
- windows下使用gcc编译boost库
- windows下使用gcc编译boost库
- Windows下使用MinGW编译boost库
- Windows下使用boost
- Windows下boost使用
- Windows下BOOST库的编译(个人备注)
- C#-WiFi共享
- 2016.10.30小鹿ins翻译
- 1027. Colors in Mars (20)
- jQuery笔记——动画设计——动画设计基础
- C#-获取磁盘,cpu,内存信息
- Boost库的使用(Windows)
- Mysql必知必会(笔记)【管理事务处理】
- C#-Web服务器
- poj 1112 Team Them Up! (补图+dp)
- 队列(1)
- Java图形化界面
- vim查看头文件和库
- Spark概述
- 检测是否为回文字符串 C++实现