我使用一个 C++ 类来封装升压::asio::io_service.
class IoService {
public:
static IoService& getInstance() {
static IoService instance;
return instance;
}
void start() {
_ioServiceThread = std::thread(&IoService::run, this);
}
void stop() {
_ioService.stop();
_ioServiceThread.join();
}
void run() {
_ioService.run();
}
private:
IoService();
~IoService();
IoService(const IoService& old) = delete;
IoService(const IoService&& old) = delete;
IoService& operator=(const IoService& old) = delete;
IoService& operator=(const IoService&& old) = delete;
boost::asio::io_service _ioService;
std::thread _ioServiceThread;
};
但是当我调用 stop 方法时,程序在连接时崩溃:
terminate called after throwing an instance of 'std::system_error'
what(): Resource deadlock avoided
Aborted
你怎么认为 ?
这是当线程尝试加入自身时出现的错误。
所以听起来你的问题是你正在打电话stop()
方法来自由调用的处理函数io_service
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)