当前位置:网站首页>Difference Between Concurrency and Parallelism
Difference Between Concurrency and Parallelism
2022-07-30 20:02:00 【a ray of sunshine】
When you learn multithreading, you will encounter a term: concurrency.This is a vocabulary in the operating system. It is necessary to understand the difference between concurrency and parallelism. I have collected several expressions from the Internet to help understand.
One:
Concurrency means that a processor handles multiple tasks at the same time.
Parallelism refers to the simultaneous processing of multiple different tasks by multiple processors or multi-core processors.
Concurrency is logically simultaneous (simultaneous), while parallelism is physically simultaneous.
Let's take an analogy: Concurrency means that one person eats three steamed buns at the same time, while parallelism means that three people eat three steamed buns at the same time.
2:
Parallel (parallel): refers to the simultaneous execution of multiple instructions on multiple processors at the same time.It's as if two people are digging a hole with a shovel each, and after an hour, each person will have a big hole.So no matter from a micro or macro point of view, the two are executed together.

Write image description here
Concurrency: It means that only one instruction can be executed at the same time, but multiple process instructions are rapidly executed in turn, so that it has the effect of multiple processes executing at the same time in the macro, but not at the same time in the micro, just divide the time into several segments, so that multiple processes can be executed alternately quickly.It's like two people using the same shovel and taking turns digging a hole. After an hour, they each dig a smaller hole. If they want to dig two larger holes, it will definitely take two hours.
Write a picture description here

Parallelism exists in multiprocessor systems, and concurrency can exist in both uniprocessor and multiprocessor systems. Concurrency can exist in uniprocessor systems because concurrency is an illusion of parallelism. Parallelism requires programs to be able to simultaneouslyMultiple operations are performed, while concurrency simply requires the program to pretend to perform multiple operations simultaneously (one operation per small time slice, multiple operations switching execution quickly).
Three:
When there are multiple threads in operation, if the system has only one CPU, it is impossible to perform more than one thread at the same time. It can only divide the CPU running time into several time periods.The time period is then allocated to each thread for execution. When the thread code of a period of time is running, other threads are in a suspended state. This method is called Concurrent.
When the system has more than one CPU, the operations of threads may be non-concurrent. When one CPU executes one thread, the other CPU can execute another thread. The two threads do not preempt each other's CPU resources and can be performed simultaneously.We call this method Parallel.
Write image description here
边栏推荐
- Start background services across processes
- Database indexes: indexes are not a panacea
- VBA runtime error '-2147217900 (80040e14): Automation error
- Day31 LeetCode
- musicApp 的.eslintrc.js
- Maxwell 一款简单易上手的实时抓取Mysql数据的软件
- 移动web开发01
- How to copy table structure and table data in MySQL
- LeetCode 0952. Calculate Maximum Component Size by Common Factor: Mapping / Union Search
- [Private Series] All kinds of strange problems encountered in daily PHP
猜你喜欢

iPhone真是十三香?两代产品完全对比,或许上一代更值得买
Database Tuning - Database Tuning

LeetCode 0952.按公因数计算最大组件大小:建图 / 并查集

How to install and use PostgreSQL 14.4

阿里面试官:给我描述一下缓存击穿的现象,并说说你的解决思路?

ELK日志分析系统

ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法

LeetCode 0952. Calculate Maximum Component Size by Common Factor: Mapping / Union Search

对int变量赋值的操作是原子的吗?

360杜跃进:太空安全风险加剧,需打造一体化防御体系
随机推荐
Typora设置标题自动标号
Redisson 的分布式锁找不到?
移动web开发01
明解C语言第七章习题
LeetCode 0952. Calculate Maximum Component Size by Common Factor: Mapping / Union Search
JUnit 5测试中的临时目录(附实例及代码)
青蛙跳台阶(递归和非递归)-------小乐乐走台阶
【PM专用】快速统计团队还有谁没有登记上报信息,快速筛选出属于自己项目组的成员,未完成XXX工作事项的名单
Brush questions record----string
MySQL mass production of data
Download and installation of the latest version of MySQL 8.0 under Linux (detailed steps)
MySQL slow query optimization
ImportError:attempted relative import with no known parent package
ELK log analysis system
[PyTorchVideo Tutorial 01] Quickly implement video action recognition
HarmonyOS笔记-----------(三)
MySQL database - DQL data query language
The technology is very powerful, do you still need to "manage up"?
“数字化重构系统,搞定 CEO 是第一步”
Mapped Statements collection does not contain value for的解决方法