以下代码在 boost::property_tree::read_xml() 调用时因段错误而崩溃。仅当在使用 boost::asio::spawn() 生成的 io_service 处理程序内部调用它时,才会发生这种情况。如果处理程序刚刚发布,则可以正常工作。有解决办法或解决方法吗?(提升1.61)
#include <boost/asio/spawn.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <iostream>
#include <sstream>
#include <thread>
void process()
{
std::cerr << "start"<< std::endl;
std::istringstream is("<t>1</t>");
boost::property_tree::ptree pt;
boost::property_tree::read_xml(is, pt); // <<< seg fault here
std::cerr << std::endl << "end" << std::endl;
}
int main()
{
boost::asio::io_service io_service;
boost::asio::spawn(io_service, [] (boost::asio::yield_context y){
process();
});
io_service.run();
return 0;
}
Run Code Online (Sandbox Code Playgroud)