赞
踩
介绍了如何在多进程间共享内存,既然是共享内存,那么久存在竞争的问题。
Boot可以通过信号量boost::interprocess::interprocess_semaphore进行多进程间的同步
1.创建信号量
#include <boost/interprocess/sync/interprocess_semaphore.hpp>
boost::interprocess::interprocess_semaphore sem{0};
其中构造参数0,用于初始化信号量的初始值
2.获取信号量
阻塞式等待:wait();
非阻塞式等待:try_wait();
最大阻塞时间式等待:timed_wait(const boost::posix_time::ptime&abs_time);
3.释放信号量
post();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。