boost通过WMI获取时间有问题

使用boost的时候。源码查看后发现boost进程通讯中使用命名队列。boost会创建一个boost_interprocess的目录并且根据磁盘启动时间创建一个子目录并且创建一个命名文件。问题就出现这个启动时间里。在启动量一万+以上的情况下。有2-3百个崩溃出现在这里。

inline bool shared_memory_object::priv_open_or_create
   (ipcdetail::create_enum_t type, const char *filename, mode_t mode, const permissions &perm)
{
   m_filename = filename;
   std::string shmfile;
   ipcdetail::create_tmp_and_clean_old_and_get_filename(filename, shmfile);


   //Set accesses
   if (mode != read_write && mode != read_only){
      error_info err = other_error;
      throw interprocess_exception(err);
   }


   switch(type){
      case ipcdetail::DoOpen:
         m_handle = ipcdetail::open_existing_file(shmfile.c_str(), mode, true);
      break;
      case ipcdetail::DoCreate:
         m_handle = ipcdetail::create_new_file(shmfile.c_str(), mode, perm, true);
      break;
      case ipcdetail::DoOpenOrCreate:
         m_handle = ipcdetail::create_or_open_file(shmfile.c_str(), mode, perm, true);
      break;
      default:
         {
            error_info err = other_error;
            throw interprocess_exception(err);
         }
   }


   //Check for error
   if(m_handle == ipcdetail::invalid_file()){
      error_info err = system_error_code();
      this->priv_close();
      throw interprocess_exception(err);
   }


   m_mode = mode;
   return true;
}

原因:主进程在boost_interprocess下根据磁盘时间戳创建目录并创建文件,子进程打开文件失败从而boost抛出异常,内部原因是boost通过wmi获取的时间变化了,导致打开文件的路径与创建文件路径不一致,从而打开文件失败。

测试:当我改变了系统时间的时候,再次运行程序。发现创建文件的目录是旧路径(旧时间戳),打开文件的目录是新路径(新的时间戳)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值