当前位置:网站首页>Difference between process and thread
Difference between process and thread
2022-07-18 15:07:00 【L7256】
reference : Threads and processes , Do you really understand _ The clouds are deep i Blog somewhere -CSDN Blog
1 process
- A process is the smallest unit of resources allocated by a system
- Process owned >= 1 Threads
- Each process uses a separate address space ; Include : Code section , Data area , Stack area , The address space between processes is isolated , They don't influence each other .
2 Process switching
Process switching will bring additional overhead : namely Context ( perform B Threads , Need to keep A Thread of thread , Take it out when executing ) Switch .
- Context preservation is specifically :1.CPU Current values in all registers 2. Save all States of the process : The state of the current process 3. Save the stack of the process .
3 Running process
Process switching involves Concurrency and parallelism
- Concurrent : Each process is assigned a Time slice : Every time CPU The length of time available to this process . This is because there is only one single core CPU, But you need to execute multiple processes . because CPU The switching and execution of processes are very fast , So it looks like multiple processes “ Run in parallel ”
- parallel : With multicore CPU Appearance , Parallelism enables real simultaneous execution of multiple tasks .
4 Threads
- Threads in the same process share the resources of the process
- Threads have their own stack area , Share the data area of the process , Code section , Heap area .
5 How the function looks in memory ( Excerpt from : What functions look like when they run in memory ? - You know )
- The function is called in the stack .
- Detailed explanation of function stack during function call _ Qin Ze's blog -CSDN Blog _ Function stack
5.1.1 Function call and return
- By function A The corresponding function in B Address , Jump into B perform . Corresponding to the function call written in the code , namely call 0x400540 ( notes :0x400540 That's the function. B The address of )
- Will function A After executing the function B() Next instruction address after push To A The stack frame , namely 0x40056a
- . function B Finished executing the code , Then execute the last instruction :ret , This function B After execution, jump to the function A Carry on . The address you jump to is 2 Step by step 0x40056a
5.1.2 function B Parameters passed in
- When the slave function A() Jump to function B() When , If you need to pass some parameters , How is this achieved ? The incoming parameters of the function originally exist in registers , But when too many parameters are passed in , Parameters will be written to the stack frame .
- function B The parameter passed in is the function A Local variables of , So parameters are existential functions A In the stack frame of .
- There is also an interview point here : Stack order of function parameters : The argument to the function is From right to left On stack
6 Address space of process runtime ( Excerpt from : How threads share process resources ? - You know )
- The stack area
No disorder between threads , It must be private , But if A Thread's local variables a, B Threads can get a,B You can also modify a
- Heap area : The code passes malloc/new Where the memory comes out
Just know the pointer of the heap , Every thread Can access the data pointed to by the pointer . So threads share the heap
- Code section : Written code compiled into executable machine instructions .
Threads share code areas , Each thread can use all functions in the code area
- Data area
Empathy : Sharing between threads .
Sum up : Threads share process resources
6 What resources are shared by threads
- Threads in the same process share all the contents of the address space of the owning process .
- The essence of thread operation is the execution of functions , And each thread has its own independence , Private stack area . At the same time, function operation requires additional registers to store information such as registers .
- Thread private : The stack area , Program counter , Stack pointer , Registers required for operation . These can be collectively referred to as Thread context
边栏推荐
- HTAP (hybrid transaction and) of polardb for PostgreSQL
- HMM & MEMM & CRF
- Go syntax - deferred call defer
- Xilinx FPGA 从spi flash启动配置数据时的地址问题
- [imaging] [9] terahertz optics - optical system
- STM32 application development practice tutorial: multi computer communication application development based on RS-485 bus
- 线程池的实现
- Language AI originally knew whether his answer was correct! New research in Berkeley and other universities is hot, netizen: dangerous, dangerous, dangerous
- (CVPR-2022)用于改进步态识别的拉格朗日运动分析和视角嵌入
- Operation of ES
猜你喜欢

03 gulimall development environment configuration

Address problem when Xilinx FPGA starts configuration data from SPI flash

函数栈帧(值得收藏)

Variables in shell scripts

Boyun was selected as the representative manufacturer of Gartner China cloud management tool market guide

Splashtop 与 Acronis 集成,提供可扩展的远程支持

【日常训练】515. 在每个树行中找最大值

MIPI CSI、DSI、UFS、C-PHY、D-PHY、M-PHY概念理解

Tensorflow2.0进阶学习-RNN生成音频 (十二)

Wechat selection and voting of finished works of applet graduation project (6) opening defense ppt
随机推荐
About mock third-party calls
选择语句 if else
Background running program method
AcWing 3540. Binary search tree binary sort tree BST
Information retrieval summit sigir2022 best paper award came out, Melbourne Institute of technology best paper, UMass University and other best short papers
后台运行程序方法
MIPI C-PHY科普
AcWing 3540. 二叉搜索树 二叉排序树 BST
[sdx62] SBL stage read GPIO status operation
综合评价方法
Vulnhub-DC8学习笔记
Wechat selection and voting of finished works of applet graduation project (7) mid term inspection report
【成像】【7】太赫兹光学——光学元件和子系统
Gee (6): set the number of decimal places reserved for the calculated value / image
【sdx62】SBL阶段读取GPIO的状态操作
【日常训练--腾讯精选50】33. 搜索旋转排序数组
el-input-number禁用科学计数无果,换成el-input(type=“number“)
Wwdc22 - Apple privacy technology exploration
C#使用Marshal.SizeOf计算结构体大小返回错误
[C language] printf formatted output and modifier summary



