boost :: interprocess_exception-创建shared_memory_object时出现library_error异常 [英] boost::interprocess_exception - library_error exception when creating shared_memory_object

查看:1070
本文介绍了boost :: interprocess_exception-创建shared_memory_object时出现library_error异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在极少数情况下(实际上是在单个客户端的计算机上),以下代码会引发异常 library_error

In some rare cases (in fact on a single client's computer) code below throws an exception "library_error":

namespace ipc = boost::interprocess;
ipc::shared_memory_object m_shm;
...
bool initAsServer(size_t sharedMemSize)
{
    ipc::permissions perm;
    perm.set_unrestricted();

    try
    {
        m_shm = ipc::shared_memory_object(
            ipc::create_only,
            CNameGenHelper::genUniqueNameUtf8().c_str(), // static std::string genUniqueNameUtf8()
            ipc::read_write, perm);
    }
    catch(const ipc::interprocess_exception& ex)
    {
        logError("failed with exception \"%s\"", ex.what());
        return false;
    }
    ...
}

在日志文件中:
[ERR]失败,出现异常 boost :: interprocess_exception :: library_error

Boost v1.58,平台win32,vs13 。

Boost v1.58, platform win32, vs13.

如果您能帮助我解决此问题,我将不胜感激。

I'll be very grateful if you help me in solving this problem. Thank you in advance!

推荐答案

问题的原因是事件ID为 6005且源名称为 EventLog的事件系统 Windows日志。
事件查看器-Windows日志-系统。
如果系统日志不包含至少一个此类事件,则方法 boost :: interprocess :: winapi :: get_last_bootup_time()返回 false boost :: interprocess :: ipcdetail :: windows_bootstamp 构造函数引发异常
(使用定义的BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME)。

Reason of problem is events with Event ID = "6005" and source name is "EventLog" in "System" Windows log. Event Viewer - Windows Logs - System. If the system log does not contain at least one such event, then method boost::interprocess::winapi::get_last_bootup_time() returns false and boost::interprocess::ipcdetail::windows_bootstamp constructor throws exception. (define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME is used).

因此,似乎足以清除系统 Windows事件日志以及所有使用Boost共享的应用程序内存将停止工作。

So it seems that it is enough to clear the "System" windows event log and any application that uses the Boost shared memory will stop working.

多么糟糕的逻辑:使用Windows事件日志的内容。
这似乎是尚未解决的boost ipc实现错误(boost_1_61_0)。

What a terrible logic: use the contents of the windows event log. It seems this boost ipc implementation bug that has not yet been fixed (boost_1_61_0).

这种情况下的临时解决方法(不重启计算机) :

My temporary workaround for this case (w/o reboot of computer):

bool fixBoostIpcSharedMem6005issue() const
{
    bool result = false;

    HANDLE hEventLog = ::RegisterEventSourceA(NULL, "EventLog");
    if(hEventLog)
    {
        const char* msg = "simple boost shared memory fix for 6005";

        if(::ReportEventA(hEventLog, EVENTLOG_INFORMATION_TYPE, 0, 6005, NULL, 1, 0, &msg, NULL))
            result = true;

        ::DeregisterEventSource(hEventLog);
    }

    return result;
}

使用它并尝试再次使用ipc :: shared_memory_object:)

Use it and try to use ipc::shared_memory_object again :)

这篇关于boost :: interprocess_exception-创建shared_memory_object时出现library_error异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆