boost asio scalability and multithreading
A library such as Boost.Asio is typically used to achieve greater efficiency. With no need to wait for an operation to finish, a program can perform other tasks in between. Therefore, it is possible to start several asynchronous operations that are all executed concurrently - remember that asynchronous operations are usually used to access resources outside of a process. Since these resources can be different devices, they can work independently and execute operations concurrently.
#include <boost/asio/io_service.hpp>
#include <boost/asio/steady_timer.hpp>
#include <chrono>
#include <thread>
#include <iostream> using namespace boost::asio; int main() {
io_service ioservice; steady_timer timer1{ioservice, std::chrono::seconds{}};
timer1.async_wait([](const boost::system::error_code& ec)
{ std::cout << "3 sec\n"; }); steady_timer timer2{ioservice, std::chrono::seconds{}};
timer2.async_wait([](const boost::system::error_code& ec)
{ std::cout << "3 sec\n"; }); std::thread thread1{[&ioservice](){ ioservice.run(); }};
std::thread thread2{[&ioservice](){ ioservice.run(); }}; thread1.join();
thread2.join(); return ;
}
both alarm clocks should ring after three seconds. Because two threads are available, both lambda functions can be executed concurrently. If the second alarm clock rings while the handler of the first alarm stock is being executed, the hanler can be executed in the second thread. If the handler of the first alarm clock has already returned, the I/O service object can use any thread to executed the second handler.
boost asio scalability and multithreading的更多相关文章
- boost::asio译文
Christopher Kohlhoff Copyright © 2003-2012 Christopher M. Kohlhoff 以Boost1.0的软件授权进行发布(见附带的LICENS ...
- Boost.Asio技术文档
Christopher Kohlhoff Copyright © 2003-2012 Christopher M. Kohlhoff 以Boost1.0的软件授权进行发布(见附带的LICENSE_1_ ...
- c++ boost asio库初学习
前些日子研究了一个c++的一个socket库,留下范例代码给以后自己参考. 同步server: // asio_server.cpp : コンソール アプリケーションのエントリ ポイントを定義します. ...
- 如何在多线程leader-follower模式下正确的使用boost::asio。
#include <assert.h> #include <signal.h> #include <unistd.h> #include <iostream& ...
- BOOST.Asio——Tutorial
=================================版权声明================================= 版权声明:原创文章 谢绝转载 啥说的,鄙视那些无视版权随 ...
- BOOST.Asio——Overview
=================================版权声明================================= 版权声明:原创文章 谢绝转载 啥说的,鄙视那些无视版权随 ...
- boost asio sync
Service: #include<boost/asio.hpp> #include<boost/thread.hpp> #include<iostream> #i ...
- 网络库crash以及boost asio strand dispath分析
最近在做服务器的稳定性的相关测试,服务器的网络底层使用的是boost asio,然后自己做的二次封装以更好的满足需求. 服务器昨天晚上发现crash了一次,之前测试了将近半个多月,有一次是莫名的退出了 ...
- boost asio tcp server 拆分
从官方给出的示例中对于 boost::asio::ip::tcp::acceptor 类的使用,是直接使用构造函数进行构造对象,这一种方法用来学习是一个不错的方式. 但是要用它来做项目却是不能够满足我 ...
随机推荐
- Matplotlib系列(四)--plt.bar与plt.barh条形图
(一)竖条条形图 参数说明 参数 说明 类型 x x坐标 int,float height 条形的高度 int,float width 线条的宽度 0~1,默认是0.8 botton 条形的起始位置 ...
- legend3---1、meedu安装
legend3---1.meedu安装 一.总结 一句话总结: 视频的安装教程做主菜,辅以文档安装教程做配料,口感甚佳. 1.为什么不直接从github下载文件的发行版,而要选择composer方式安 ...
- Win32下session和window station以及desktop一些介绍和应用
会话(session).工作站(WindowStation).桌面(Disktop).窗口(window) https://blog.csdn.net/hlswd/article/details/77 ...
- 凉经-乐糖游戏-PHP开发实习生
收到面试通知当天因为学校出事要求我明天必须回去,所以就买当晚的火车票,然后跟公司说学校有事明天没法去面试了,公司人事比较好给我安排到当天下午面试.公司规模不是很大,但位置好下了地铁到,可能因为招的是实 ...
- 为什么从pycharm中打开的html文件会显示404?
问题如图: 解决办法: 某次发现运行导入的html文件的时候,打开浏览器会报404错误:而运行自己写的html文件则正常显示:最后发现这是pycharm缓存问题,只需重启pycharm清除缓存就ok啦 ...
- SqlServer 事物
Ø 事务 在数据库中有时候需要把多个步骤的指令当作一个整体来运行,这个整体要么全部成功,要么全部失败,这就需要用到事务. 1. 事务的特点 事务有若干条T-SQL指令组成,并且所有的指令昨晚一个整体提 ...
- Ubuntu下面怎么连接drcom校园网?(重庆大学实测可行)
之前因为ubuntu下面不能连drcom接校园头疼了半天,我们学校自带的客户端成功运行了,但是还是不能上网.\ 于是我百度了半天,搜了一堆教程...因为技术太渣好多教程里面不会修改参数,然后都不能成功 ...
- Pikachu漏洞练习平台实验——RCE(五)
1.概述 RCE(Remote Command/Code Execute) 给攻击者向后台服务器远程注入操作系统命令或者代码,从而控制后台系统. 远程系统命令执行一般出现这种漏洞,是因为应用系统从设计 ...
- JavaScript.import
// --file.js-- function getJSON(url, callback) { let xhr = new XMLHttpRequest(); xhr.onload = fu ...
- [LOJ3123] CTSC2019重复
Description 给定一个⻓为 n 的字符串 s , 问有多少个⻓为 m 的字符串 t 满足: 将 t 无限重复后,可以从中截出一个⻓度为 n 且字典序比 s 小的串. m ≤ 2000 n ≤ ...