当前位置: 首页 > news >正文

泉州中企网站做的好吗创意设计报告

泉州中企网站做的好吗,创意设计报告,金属加工网站建设,怎么做挣钱的网站介绍 named_mutex是一个进程锁#xff0c;考虑到进程和线程之间的区别区别#xff1a;一个工作单元要想被称作进程#xff0c;它必须要有操作系统指派给他的地址空间#xff0c;必须拥有进程ID#xff0c;必须拥有状态和进程表中的表项。进程和线程之间最大的区别是进程有…介绍 named_mutex是一个进程锁考虑到进程和线程之间的区别区别一个工作单元要想被称作进程它必须要有操作系统指派给他的地址空间必须拥有进程ID必须拥有状态和进程表中的表项。进程和线程之间最大的区别是进程有着自己的地址空间而线程共享创建它们的进程的地址空间。本例子是使用多线程的方式来测进程锁的线程安全等一切结束的时候好好总结一下完善这个大坑 代码 #include boost/thread/thread.hpp #include boost/interprocess/sync/scoped_lock.hpp #include boost/interprocess/sync/named_mutex.hpp #include boost/ref.hpp#include string #include mutex//boost::shared_mutex global_mutex; int global_num 10;//全局变量写者改变全局变量读者读全局变量 namespace bip boost::interprocess; bip::named_mutex global_mutex(bip::open_or_create,mtx);//读线程 void read_thread(std::string name){boost::lock_guardbip::named_mutex lock(global_mutex);//读锁定 // bip::named_mutex global_mutex(bip::open_or_create,mtx); // global_mutex.lock();printf(线程%s抢占了资源global_num %d\n,name.c_str(),global_num);boost::this_thread::sleep(boost::posix_time::seconds(1));printf(线程%s释放了资源...\n,name.c_str()); // global_mutex.unlock(); }//写线程 void write_thread(std::string name){std::lock_guardbip::named_mutex lock(global_mutex);//写锁定 // bip::named_mutex global_mutex(bip::open_or_create,mtx); // global_mutex.lock();global_num;//写线程改变数据的数值printf(线程%s抢占了资源global_num %d\n,name.c_str(),global_num);boost::this_thread::sleep(boost::posix_time::seconds(1));printf(线程%s释放了资源...\n,name.c_str()); // global_mutex.unlock(); }int main(){std::string read_thread_r1 read_thread_r1;std::string read_thread_r2 read_thread_r2;std::string read_thread_r3 read_thread_r3;std::string read_thread_r4 read_thread_r4;std::string read_thread_r5 read_thread_r5;std::string write_thread_w1 write_thread_w1;std::string write_thread_w2 write_thread_w2;boost::thread_group tg;tg.create_thread(boost::bind(read_thread,boost::ref(read_thread_r1)));tg.create_thread(boost::bind(read_thread,boost::ref(read_thread_r2)));tg.create_thread(boost::bind(read_thread,boost::ref(read_thread_r3)));tg.create_thread(boost::bind(read_thread,boost::ref(read_thread_r4)));tg.create_thread(boost::bind(read_thread,boost::ref(read_thread_r5)));tg.create_thread(boost::bind(write_thread,boost::ref(write_thread_w1)));tg.create_thread(boost::bind(write_thread,boost::ref(write_thread_w2)));tg.join_all();return 0; } 参考链接 使用boost.threads的condition构造的读写锁
http://www.pierceye.com/news/284512/

相关文章:

  • 网站的透明图片怎么做嘉兴网站托管
  • 宝安做棋牌网站建设哪家便宜wordpress 导出html5
  • 网页制作与网站建设的发展趋势设想wordpress必装插件
  • 网站模板下载百度云链接怎么做的学做粤菜的网站
  • 牛栏前网站建设整站优化推广品牌
  • 太原做网站找谁阳江公司做网站
  • 企业网站aspwordpress原生相册
  • 重庆网站建设哪家公司那家好企业宣传软文
  • 如何选择营销网站建设什么网站做优化最好?
  • 个人博客网站模板素材网站的运营方案
  • wordpress增加网站网页关键词jquery验证网站地址
  • 企业招聘网站模板网站页面设计需要遵循的六大原则
  • 网站界面设计说明关键词排名顾问
  • 滨江区网站开发公司贵阳住房和城乡建设局网站
  • 如何建设小网站邢台市天气预报15天
  • 网站收录量低怎么做舟山公司网站制作
  • 部队网站模板计算机网站建设员
  • 对象储存做网站微博内网站怎么做的
  • 运城做网站要多少钱谷歌网站英文
  • 校园网站建设的意见与建议做儿童交互网站
  • 7黄页网站建设网站建设培训会讲话
  • 百度推广公司地址苏州优化方式
  • 做一个电商网站建设银行网站打不开用什么浏览器
  • 保定住房和城乡建设局网站沙洋网站定制
  • 北京电脑培训网站网站首页怎么做全屏swf
  • 网站建设 设计 优化 维护爱站网关键词挖掘工具
  • 做电影收费网站二级域名查询
  • 销售网站模板a5站长网网站交易
  • 网站需要怎么做的吗做营销网站那个好
  • 苏州网站建设软件收费广东网站设计哪家专业