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

响应式网站自助建站google官网下载

响应式网站自助建站,google官网下载,企业展示型网站怎么建,网站优缺点结构 Whats A Semaphore?Boost.Interprocess Semaphore Types And HeadersAnonymous semaphore example Whats A Semaphore? 旗语是一种基于内部计数的进程间同步机制#xff0c;它提供了两种基本操作。等待#xff1a;测试旗语数的值#xff0c;如果小于或等于0#x…结构 Whats A Semaphore?Boost.Interprocess Semaphore Types And HeadersAnonymous semaphore example Whats A Semaphore? 旗语是一种基于内部计数的进程间同步机制它提供了两种基本操作。等待测试旗语数的值如果小于或等于0则等待否则递减旗语数。Post增加旗语数。增加信号量 如果有进程被阻塞则唤醒其中一个进程。如果初始旗语数被初始化为1则Wait操作相当于mutex锁定Post相当于mutex解锁。这种类型的semaphore被称为二进制semaphore。虽然旗语可以像mutexes一样使用但它们有一个独特的特点与mutexes不同Post操作不需要由执行Wait操作的同一个线程/进程执行。 Boost.Interprocess Semaphore Types And Headers Boost.Interprocess offers the following semaphore types:#include boost/interprocess/sync/interprocess_semaphore.hppinterprocess_semaphore: An anonymous semaphore that can be placed in shared memory or memory mapped files.interprocess_semaphore。一个匿名的信号体可以放在共享内存或内存映射文件中。#include boost/interprocess/sync/named_semaphore.hppnamed_semaphore: A named semaphore.named_semaphore。一个命名的旗语。 Anonymous semaphore example We will implement an integer array in shared memory that will be used to transfer data from one process to another process. The first process will write some integers to the array and the process will block if the array is full.The second process will copy the transmitted data to its own buffer, blocking if there is no new data in the buffer.This is the shared integer array (doc_anonymous_semaphore_shared_data.hpp):我们将在共享内存中实现一个整数数组用于从一个进程向另一个进程传输数据。第一个进程将向数组写入一些整数如果数组已满该进程将阻塞。第二个进程将把传输的数据复制到自己的缓冲区如果缓冲区中没有新的数据则阻塞。这就是共享整数数组(doc_anonymous_semaphore_shared_data.hpp)。 #include boost/interprocess/sync/interprocess_semaphore.hppstruct shared_memory_buffer {enum { NumItems 10 };shared_memory_buffer(): mutex(1), nempty(NumItems), nstored(0){}//Semaphores to protect and synchronize accessboost::interprocess::interprocess_semaphoremutex, nempty, nstored;//Items to fillint items[NumItems]; }; 这是进程主进程。创建共享内存将整数数组放置在那里并逐个开始整数如果数组满了则阻塞。 #include boost/interprocess/shared_memory_object.hpp #include boost/interprocess/mapped_region.hpp #include iostream #include doc_anonymous_semaphore_shared_data.hppusing namespace boost::interprocess;int main () {//Remove shared memory on construction and destructionstruct shm_remove{shm_remove() { shared_memory_object::remove(MySharedMemory); }~shm_remove(){ shared_memory_object::remove(MySharedMemory); }} remover;//Create a shared memory object.shared_memory_object shm(create_only //only create,MySharedMemory //name,read_write //read-write mode);//Set sizeshm.truncate(sizeof(shared_memory_buffer));//Map the whole shared memory in this processmapped_region region(shm //What to map,read_write //Map it as read-write);//Get the address of the mapped regionvoid * addr region.get_address();//Construct the shared structure in memoryshared_memory_buffer * data new (addr) shared_memory_buffer;const int NumMsg 100;//Insert data in the arrayfor(int i 0; i NumMsg; i){data-nempty.wait();data-mutex.wait();data-items[i % shared_memory_buffer::NumItems] i;data-mutex.post();data-nstored.post();}return 0; } The second process opens the shared memory and copies the received integers to its own buffer: #include boost/interprocess/shared_memory_object.hpp #include boost/interprocess/mapped_region.hpp #include iostream #include doc_anonymous_semaphore_shared_data.hppusing namespace boost::interprocess;int main () {//Remove shared memory on destructionstruct shm_remove{~shm_remove(){ shared_memory_object::remove(MySharedMemory); }} remover;//Create a shared memory object.shared_memory_object shm(open_only //only create,MySharedMemory //name,read_write //read-write mode);//Map the whole shared memory in this processmapped_region region(shm //What to map,read_write //Map it as read-write);//Get the address of the mapped regionvoid * addr region.get_address();//Obtain the shared structureshared_memory_buffer * data static_castshared_memory_buffer*(addr);const int NumMsg 100;int extracted_data [NumMsg];//Extract the datafor(int i 0; i NumMsg; i){data-nstored.wait();data-mutex.wait();extracted_data[i] data-items[i % shared_memory_buffer::NumItems];data-mutex.post();data-nempty.post();}return 0; } The same interprocess communication can be achieved with a condition variables and mutexes, but for several synchronization patterns, a semaphore is more efficient than a mutex/condition combination.同样的进程间通信可以用条件变量和mutexes来实现但对于几种同步模式semaphore比mutex/条件组合更有效率。
http://www.huolong8.cn/news/164853/

相关文章:

  • 网站建设公司平台动漫设计与制作专业学什么
  • 常用网站开发语言太原网页制作公司
  • 嘉兴 企业网站 哪家为什么建设网银网站打不开
  • 做网站需要服务器吗深圳网站建设 公司元
  • 宿州做网站电商哪个平台销量最好
  • 网站后台管理系统下载wordpress顶部图像修改
  • 蒙狼科技建设网站好不好福州网站设计外包
  • 福田网站建设设计公司哪家好wap网站 html5
  • 用tomcat做网站目录典型的o2o平台有哪些
  • sns电商网站114网址大全
  • 凡科网做网站教程php网站开发学校
  • 扬州有做义工的地方或网站嘛wordpress最大上传2g
  • dz网站如何搬家优惠劵精选网站怎么做
  • 领导视察网站建设wordpress如何实现登录注册功能
  • 免费asp主机网站wordpress双语模板
  • 网站建设空格怎么打wordpress 文章找不到
  • 帝国cms 调用网站名称北京昨天出啥大事了
  • 怎么做物流网站代理好的网站建设平台
  • 招聘信息网站怎么做做酒店网站
  • 企业网站建设的基本内容岐山县住房和城市建设局网站
  • 购物商城排名深圳宝安seo
  • 网站导航做网站必须要虚拟主机吗
  • 织梦网站后台文章编辑美化代码庆安建设局网站
  • 做网站做哪个行业好wordpress 随机点击数
  • 金融公司网站建设模板河南省建设部网站
  • 网页设计共享网站上海企业网站建设服务
  • 亚洲做爰直播网站vip影视建设网站官网
  • 网站从新建设影响收录么营销网站建设一薇
  • 河北电子商务网站建设央企网站群建设
  • 长春企业自助建站哈尔滨网站建设价格低