boost的初始化失败错误Boost shared memory can't be initialized

在6月26号,遇到一个问题。

与boost相关。

但因为没有相关的部分的源代码,所以只能去google去找。

看到一个在stack overflow上的贴子,似乎有些可能性。


当时的情况是,不是所有的机器都会出这个错误。只要某台机器上。


网上这个描述如下:


I found solution here boost::interprocess_exception - library_error exception when creating shared_memory_object
It's a bit weird, but here boost relies on Windows Event Logger. And if there is no event with ID = 6005. It throws an exception.
The code snippet from the boost 1.62.0 win32_api.hpp
//Obtains the bootup time from the System Event Log,
//event ID == 6005 (event log started).
//Adapted from http://msdn.microsoft.com/en-us/library/windows/desktop/bb427356.aspx
inline bool get_last_bootup_time(std::string &stamp)
{
   const char *source_name = "System";
   const char *provider_name = "EventLog";
   const unsigned short event_id = 6005u;
The solution was just to add the event 6005 and all work again fine.


===========================================

注意上面的文字,有两个信息,引起我的注意:

1)事件查看器

2)6005


==========================================

然后,大致了解到boost这样做的目的是为了取得系统开始工作的时间,也就是开机的时间。

见下图,正常的电脑如下:



但是,出现错误情况的电脑,在上图左侧的“系统”的位置,是一个红叉。

无法打开。

清空后,重启电脑,可以进入,并且找到6005,一切正常。


=========================================

其它:

1)想要复现该错误,很简单 ,只要清空事件,就会出现。也就是说boost如果找不到6005,就会出错。

当然,这是一个bug。

-----------------------------------------------------------------------

2)从合理性角度来说,boost这样实现,有些欠妥。



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值