Boost Thread Access Violation in Boost Log on shut

2019-05-05 07:32发布

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条回答
混吃等死
2楼-- · 2019-05-05 08:00

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();

    // ...
}
查看更多
登录 后发表回答