当前位置:网站首页>boost asio的work作用
boost asio的work作用
2022-04-21 13:29:00 【Hello,C++!】
要想实现异步操作,就需要提供一个环境,这个环境是
boost::asio::io_service io_service_;
io_service_.run();
但是io_service_.run(),是不阻塞的,这个环境是需要io_service_.run()阻塞运行的,于是需要改成这样
boost::asio::io_service io_service_;
boost::asio::io_service::work work_(io_service_);
io_service_.run();
用io_service构造出一个work之后,再执行io_service_.run();就是阻塞的了。但是主线程不可以阻塞,否则后面的代码没法执行了,于是需要继续改
boost::asio::io_service io_service_;
boost::asio::io_service::work work_(io_service_);
boost::thread th(run_io);
void run_io()
{
io_service_.run();
}
work: 可以防止io_service里注册的所有事件完成时退出事件循环。
版权声明
本文为[Hello,C++!]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_23350817/article/details/124242471
边栏推荐
- 【数字信号处理】线性常系数差分方程 ( 使用 matlab 求解 “ 线性常系数差分方程 “ 示例 | A 向量分析 | B 向量分析 | 输入序列分析 | matlab 代码 )
- 农产品期货品种有哪些呢?
- Blazor 的 NavLink 的 NavLinkMatch.Prefix 有啥作用
- Wang Baiping: my way to envoy maintainer
- Filter and listener listeners
- 【csnote】db异常(冗余数据、修改异常、删除异常、插入异常)
- 一级等保怎么做?要收费吗?等保要求是什么?
- OJ每日一练——分段函数
- no server suitable for synchronization found
- Detailed explanation and demonstration of 3-4dom shaped XSS
猜你喜欢

哈夫曼编码

【数字信号处理】线性常系数差分方程 ( 使用 matlab 求解 “ 线性常系数差分方程 “ 示例 | A 向量分析 | B 向量分析 | 输入序列分析 | matlab 代码 )

如何在Centos下卸载OpenJDK,安装Oracle JDK

Getting started with Xcode cloud: pull request (PR) workflow

Baidu map development custom information window openinfowindow style

Jiaozuo Third People's Hospital joined hands with meichuang to open a new situation of data security construction

idea自动生成单元测类

HCIP之路OSPF拓展配置

乡村vlog收割8000w+播放,又一个流量天花板?

Read fast RCNN
随机推荐
Communication sliding window
启牛商学院的课程让小白开户购买国债逆回购,安全嘛?
LLVM之父Chris Lattner:编译器的黄金时代
Redis - breakdown, penetration, avalanche
万字干货!帮你深度掌握设计中的「光影」知识点
单体测试使用Assert.assertThat(expected,Matcher matcher)来对比结果和预期
一级等保怎么做?要收费吗?等保要求是什么?
【csnote】db异常(冗余数据、修改异常、删除异常、插入异常)
no server suitable for synchronization found
哈夫曼编码
PostgreSQL 15即将支持SQL标准中的MERGE语句
JDBC 驱动升级到 Version 8.0.28 连接 MySQL 的踩坑记录
焦作市第三人民医院携手美创,开启数据安全建设新局面
[digital signal processing] correlation coefficient (concept of correlation coefficient | energy signal and power signal | causality of system)
S: Unit gain compensation
Build a service registration and Discovery Center
通讯录的动态实现
Getting started with Xcode cloud: pull request (PR) workflow
leetcode:824. 山羊拉丁文【简单字符串操纵】
Revit secondary development - contact filtration (phase 17)