Boost Thread Access Violation in Boost Log on shutdown

試著忘記壹切 提交于 2020-01-02 05:32:17

问题


I have an application that uses boost logging. During shutdown, it gets an access violation on a null pointer access. When I step through the code to the point of failure, it appears that the boost::log dll is being de-allocated and then boost::thread code tries to access the memory that was once occupied by the log dll.

I am not using any boost threads in my own code, and so assume the boost-thread dll is used by boost log.

To ensure all sinks are destroyed prior to shutdown, I am calling: core->flush() and core->remove_all_sinks()

I am using boost 1.60 and have also tried this with boost 1.63. Same result.

Is there a way to ensure the boost logging core is shut down fully before exit / unload the dlls?


回答1:


This problem might be with locale object set by the boost system. Similarly in your case this locale might be getting destroyed before Boost.Log is deinitialized, which results in a crash.

As per boost docs particularly log file rotation module. They have provided a workaround for similar case Boost known issues

Solution would be to initialize locale in main loop so that boost will have enough cycles to make cleanup at the end.

int main(int argc, char* argv[])
{
    boost::filesystem::path::imbue(std::locale("C"));
    initialize_log();

    // ...
}


来源:https://stackoverflow.com/questions/42308084/boost-thread-access-violation-in-boost-log-on-shutdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!