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 类的使用,是直接使用构造函数进行构造对象,这一种方法用来学习是一个不错的方式. 但是要用它来做项目却是不能够满足我 ...
随机推荐
- HDU6424 Rikka with Time Complexity
HDU6424 Rikka with Time Complexity 数学题~(真的数学题) #include <bits/stdc++.h> #define mp(_,__) make_ ...
- Mac定制终端:iTerm2 + zsh + powerline
原始界面: 配置后的界面: 安装iTerm2 可以直接去官网下载:https://www.iterm2.com/ 下载后直接安装即可 安装主题 所有主题:https://iterm2color ...
- sql查询XML
--查询Extra里节点UName值等于“黄”的所有信息 select * from t_UserPayLog where Extra.exist('//UName[.="黄"]' ...
- Delphi 文件转换Base64
uses EncdDecd; function FileToBase64(FileName: string): string; var MemoryStream: TMemoryStream;beg ...
- 【ABAP系列】SAP ABAP基础-abap数据类型的解析整理
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP基础-abap数 ...
- JUnit的基本使用
一些关于单元测试的理念: 单元测试并不能证明你的代码是正确的,只能证明你的代码是没有错误的. Keep bar green and keep your code cool 关于JUnit的 ...
- css圣杯布局
HTML <div class="container"> <div class="content">content</div> ...
- JavaWeb学习——session总结
一.session简介 sesion也就是会话,Session对象存储特定用户会话所需的属性及配置信息.这样,当用户在应用程序的Web页之间跳转时,存储在Session对象中的变量将不会丢失,而是在整 ...
- 9、numpy——数组操作
Numpy 中包含了一些函数用于处理数组,大概可分为以下几类: (1)修改数组形状 (2)翻转数组 (3)修改数组维度 (4)连接数组 (5)分割数组 (6)数组元素的添加与删除 1.修改数组形状 函 ...
- HDU 6315 Naive Operations 【势能线段树】
<题目链接> 题目大意: 给出两个序列,a序列全部初始化为0,b序列为输入值.然后有两种操作,add x y就是把a数组[x,y]区间内全部+1,query x y是查询[x,y]区间内∑ ...