Comments (2)
在你读完我上一篇文章C++20: 协程一瞥之后,今天我更为详细地再谈一下协程。
再一次,我们再C++20中没有见到coroutines(协程),但是我们可以创造一些框架来实现协程。
这篇以及后续的文章中我将介绍一个实现协程的框架。最终,你将创造一个你自己的,或者使用一个已经存在的协程实现(比如: Lewis Baker的天才之作:cppcoro
今天这篇文章是中间的一篇:这篇文章不是概述,但也不是深入探讨。下一篇文章将深入探讨协程框架。
你的第一个问题:什么时候我应该使用协程?
from blog.
典型的使用场景
协程通常用于编写事件驱动的应用,事件驱动应用可以是仿真、游戏、服务器、UI甚至算法。例如,几年前我用Python为去纤颤器写了一个仿真程序。这个仿真程序帮助我们临床研究。去纤颤器是一个事件驱动应用,我基于Python的twisted框架实现了它。
协程也用于多任务协作。
Coroutines are also typically used for cooperative multitasking. The key to cooperative multitasking is that each task takes as much time as it needs. Cooperative multitasking stands in contrast to preemptive multitasking, for which we have a scheduler that decides how long each task gets the CPU. Cooperative multitasking makes concurrency often easier because a concurrent job can not be interrupted in a critical region. If you are still puzzled with the terms cooperative and preemptive, I found an excellent overview and read here: Cooperative vs. Preemptive: a quest to maximize concurrency power
from blog.
Related Issues (20)
- 计算广告学:目录
- 计算广告学: 广告的基本知识 HOT 10
- Tweet HOT 2
- 计算广告学:合约广告系统 HOT 6
- 2018,人生是一条蛇,它咬着自己的尾巴 HOT 11
- 为什么我说C/C++程序员都要阅读Redis源码之:通过Redis学习事件驱动设计 HOT 5
- 《这就是搜索引擎》读书笔记:网页作弊
- 高山仰之可极,谈半同步/半异步网络并发模型
- 也谈C++:重剑无锋,大巧不工
- [译]C++天问! HOT 4
- [译]C++20: 协程一瞥 HOT 4
- 知我者,知乎也 HOT 13
- TBB:quick start HOT 2
- C++转型对比
- [译]C++20:协程实现无限数据流 HOT 1
- conda入门
- 关于分布式中CAP的反思
- Faiss: Quick Start HOT 1
- brpc安装
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.