boost - 加入线程:“避免资源死锁”
问题描述
我使用一个封装了boost::asio::io_service的 c++ 类。
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
.
推荐阅读
- python - 无法在以“==”结尾的 conda 中保存环境变量
- angular - 如何在 Angular 6 中为不同的 ng-select 使用默认主题和材质主题
- sql-server - 为什么当使用 - where columnName like N'%ဲ010%' 进行搜索时,SQL 会同时返回 2010 和 010
- javascript - 按索引访问 localStorage 数组
- python - 计算三平方定理的 Python 代码
- ansible - 带有 shell 模块的剧本中的 Ansible 命令
- ios - 当目标是 ios 11.0 或字母时在 Xcode 11.3 中访问 UIWindow 实例
- ruby-on-rails - rake routes 显示路由.. 但我得到 ActionController::RoutingError(no route error)
- selenium - 如何使用 Selenium IDE 验证下拉列表中存在的选项?
- amazon-ec2 - 连接 Amazon RDS SQL Server 数据库时超时