boost的named_mutex的一些坑 - 小众知识

boost的named_mutex的一些坑

2022-08-12 01:37:00 苏内容
  标签: boost
阅读:2021

最近遇到一个问题,程序在a用户下运行后,然后注销windows,登陆b用户,发现程序奔溃,抓了下堆栈,发现了boost的named_mutex一些细节,记录下


#include <boost/interprocess/sync/named_mutex.hpp>

#include <boost/interprocess/creation_tags.hpp><br>

boost::interprocess::named_mutex mutex(boost::interprocess::open_or_create, "haha");



 1.这段代码在a用户运行后,注销,在运行b用户,直接崩溃


 解决方案

boost::interprocess::permissions per;

per.set_unrestricted();

boost::interprocess::named_mutex mutex(boost::interprocess::open_or_create, "haha",per);



 文件中的几个值的意义


 UninitializedSegment, //0


 InitializingSegment, //1


 InitializedSegment, //2


 CorruptedSegment //3


 定义在boost\interprocess\detail\managed_open_or_create_impl.hpp


 开始初始化为1,进程退出的时候改为2


  


 2.文件创建在priv_open_or_create函数里面,其中文件夹在create_device里面创建,该函数最终调用


 get_last_bootup_time(boost\interprocess\detail\win32_api.hpp) 函数会根据系统的事件来获取启动时间,


 如果进程启动之前,系统的日志被一些清理工具清理掉了,那么就会触发异常 


扩展阅读
相关阅读
© CopyRight 2010-2021, PREDREAM.ORG, Inc.All Rights Reserved. 京ICP备13045924号-1