码迷,mamicode.com
首页 > 其他好文 > 详细

boost::interprocess(1)

时间:2014-05-15 16:05:06      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   c   

bubuko.com,布布扣
发送端:
#include <iostream> #include <windows.h> #include <string> using namespace std; #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/mapped_region.hpp> #include <thread> using namespace boost::interprocess; int num = 0; mapped_region *mp_r; void funs() { while (1) { num ++; memcpy(mp_r->get_address(), &num, sizeof(int)); mp_r->get_address(); Sleep(500); } } int main(int argc, char*argv[]) { shared_memory_object share_obj(create_only, "named_obj", read_write); share_obj.truncate(sizeof(int)); mp_r = new mapped_region(share_obj, read_write); std::thread th(funs); th.detach(); getchar(); return 0; }
bubuko.com,布布扣
bubuko.com,布布扣
接收端:
#include <iostream> #include <string> #include <windows.h> using namespace std; #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/mapped_region.hpp> #include <thread> using namespace boost::interprocess; mapped_region* mp_r; void fung() { while (1) { int num = 0; memcpy(&num, static_cast<char*>(mp_r->get_address()), sizeof(int)); cout<<num<<endl; Sleep(500); } } void main(int argc, char *argv[]) { //open shared memory object shared_memory_object share_obj(open_only, "named_obj", read_only);//map the shared memory object to current process mp_r = new mapped_region(share_obj, read_only); std::thread th(fung); th.detach(); getchar(); //remove shared memory object shared_memory_object::remove("named_obj"); }
bubuko.com,布布扣

 

boost::interprocess(1),布布扣,bubuko.com

boost::interprocess(1)

标签:style   blog   class   code   java   c   

原文地址:http://www.cnblogs.com/zzyoucan/p/3726488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!