当前位置:网站首页>What are the relationships and differences between threads and processes
What are the relationships and differences between threads and processes
2022-04-23 18:03:00 【OceanKeeper1215】
Thread definition
Thread is the basic execution unit of a process , All tasks of a process are executed in threads
The process wants to perform the task , There must be threads , The process must have at least one thread
The program will start a thread by default , This thread is called the main thread or UI Threads
Process definition
A process is an application running in the system
Each process is independent , Each process runs in its own dedicated and protected memory
The difference between a process and a thread
address space : Threads of the same process share the address space of this process , And there is an independent address space between processes .
Resource ownership : Threads in the same process share the resources of the process ( Such as memory 、I/O、cpu etc. ), But the resources between processes are independent .
After a process crashes , No impact on other processes in protected mode , But when a thread crashes, the whole process dies . So multiprocessing is more robust than multithreading .
Process switching , It consumes a lot of resources , Efficient . So when it comes to frequent switching , It's better to use threads than processes . Also, if concurrent operations of some variables are required to be performed at the same time and shared at the same time , Only threads, not processes
Execution process : Each independent process has an entry for the program to run 、 Sequential execution sequence and program entry . But the thread cannot execute independently , Must exist in the application , Multiple thread execution control provided by the application .
Threads are the basic unit of processor scheduling , But the process is not .
advantage
It can improve the efficiency of program execution
It can improve the utilization rate of resources (CPU, Memory )
When the task on the thread is finished , The thread will automatically destroy
shortcoming
Starting a thread requires a certain amount of memory space ( By default , Every thread takes up 512 KB)
If you start a lot of threads , It takes up a lot of memory space , Reduce the performance of the program
More threads ,CPU The higher the overhead on the calling thread
Programming is more complicated , For example, communication between threads 、 Multithreaded data sharing
版权声明
本文为[OceanKeeper1215]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230545104956.html
边栏推荐
- .105Location
- Scikit learn sklearn 0.18 official document Chinese version
- Docker installation MySQL
- Go language JSON package usage
- xlsxwriter. exceptions. Filecreateerror: [errno 13] permission denied
- Vite configure proxy proxy to solve cross domain
- Cross domain settings of Chrome browser -- including new and old versions
- C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
- Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise
- Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
猜你喜欢
QTableWidget使用讲解
Scikit learn sklearn 0.18 official document Chinese version
ArcGIS license error -15 solution
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
.104History
The ultimate experience, the audio and video technology behind the tiktok
Docker 安装 MySQL
Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战
2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
Auto. JS custom dialog box
随机推荐
Map basemap Library
Go对文件操作
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
C1 notes [task training part 2]
re正則錶達式
2022江西储能技术展会,中国电池展,动力电池展,燃料电池展
positioner
Docker 安装 MySQL
Dock installation redis
2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
A few lines of code teach you to crawl lol skin pictures
undefined reference to `Nabo::NearestNeighbourSearch
JS get link? The following parameter name or value, according to the URL? Judge the parameters after
列表的使用-增删改查
Add animation to the picture under V-for timing
Timestamp to formatted date
20222 return to the workplace
cartographer_ There is no problem compiling node, but running the bug that hangs directly
ArcGIS table to excel exceeds the upper limit, conversion failed
C language array processing batch data