CP.4: Think in terms of tasks, rather than threads
CP.4:按照任务思考问题,而不是线程
Reason(原因)
A thread is an implementation concept, a way of thinking about the machine. A task is an application notion, something you'd like to do, preferably concurrently with other tasks. Application concepts are easier to reason about.
线程是实现层面的概念,一种理解机器动作的方式。任务是应用层面的观念,你希望它可以和其他任务并发执行。应用概念更容易理解。
Example(示例)
Note(注意)
With the exception of async(), the standard-library facilities are low-level, machine-oriented, threads-and-lock level. This is a necessary foundation, but we have to try to raise the level of abstraction: for productivity, for reliability, and for performance. This is a potent argument for using higher level, more applications-oriented libraries (if possibly, built on top of standard-library facilities).
除了async()以外,标准库功能都是低层次,面向机器,线程/锁层次的。这些作为基础有必要,但是我们必须努力提高抽象的层次:为了生产性,为了可靠性,也为了性能。这是一个事关使用更高层次,更加面向应用的库的具有重大影响的话题(如果可能,将其构建在标注库功能的顶层)。
Enforcement(实施建议)
???
原文链接
https:///isocpp/CppCoreGuidelines/blob/master/#cp4-think-in-terms-of-tasks-rather-than-threads
新书介绍
以下是本人3月份出版的新书,拜托多多关注!

本书利用Python 的标准GUI 工具包tkinter,通过可执行的示例对23 个设计模式逐个进行说明。这样一方面可以使读者了解真实的软件开发工作中每个设计模式的运用场景和想要解决的问题;另一方面通过对这些问题的解决过程进行说明,让读者明白在编写代码时如何判断使用设计模式的利弊,并合理运用设计模式。
对设计模式感兴趣而且希望随学随用的读者通过本书可以快速跨越从理解到运用的门槛;希望学习Python GUI 编程的读者可以将本书中的示例作为设计和开发的参考;使用Python 语言进行图像分析、数据处理工作的读者可以直接以本书中的示例为基础,迅速构建自己的系统架构。
觉得本文有帮助?欢迎点赞并分享给更多的人。
阅读更多更新文章,请关注微信公众号【面向对象思考】
















