当前位置:网站首页>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
边栏推荐
猜你喜欢

C1小笔记【任务训练篇二】

Implementation of object detection case based on SSD

Gobang game based on pyGame Library

Cloud native Virtualization: building edge computing instances based on kubevirt

2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展

ArcGIS table to excel exceeds the upper limit, conversion failed

Welcome to the markdown editor

2022 Shanghai safety officer C certificate operation certificate examination question bank and simulation examination

MySQL_01_简单数据检索

云原生虚拟化:基于 Kubevirt 构建边缘计算实例
随机推荐
C [file operation] read TXT text by line
Pyppeter crawler
Fashion classification case based on keras
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
Amount input box, used for recharge and withdrawal
Nat commun | current progress and open challenges of applied deep learning in Bioscience
开源按键组件Multi_Button的使用,含测试工程
ArcGIS license error -15 solution
mysql自动启动设置用Systemctl start mysqld启动
Re regular expression
2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition
ES6
journal
Gaode map search, drag and drop query address
Go file operation
Queue solving Joseph problem
2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
How to read literature
Multi thread crawling Marco Polo network supplier data