当前位置:网站首页>44. Concurrent programming theory
44. Concurrent programming theory
2022-07-03 19:50:00 【Python_ twenty-one】
List of articles
1. Procedures and processes
A program is a code file , Process refers to the running process of a program .
The same program is executed many times , It's multiple processes .
process :CUP The process of executing a program .
There are many tasks to be performed at the same time , however cpu There can only be one thing at a time .
2. The program runs in three states
When the program is created and executed , The first thing to enter is the ready state , Wait for the operating system scheduling to start running .
Encountered in execution I/O The event request of the operation will enter the blocking state , Wait for the result .
After getting the return, instead of running immediately, it enters the ready state and waits for the operating system to call ready to run again .
3. Concurrency and parallelism
Concurrent : It's pseudo parallelism , It feels like it's running at the same time , Single cpu+ Implementation of multi-channel technology , Parallel also belongs to concurrent .
Multi channel technology can realize cpu Division of time slice of each program process , Each program is executed for a period of time , Switch between different programs , Too fast , It makes people feel that they are running at the same time .
parallel : Really run at the same time , need cpu With multi-core .
A kernel performs a task . When there are more tasks than the kernel , Only when the first few tasks are executed I/O Interrupt execution , Will be assigned to other tasks for temporary execution ,I/O The end operating system will call it again .
Today's computers run multiple tasks at the same time , A task can be understood as a process .
The concurrent implementation of a process is that the hardware interrupts a running process , Save all the states in the program at this time , The operating system will record in a process table ( Each process occupies a process representation , These entries are also called process control modules ) Ensure that the program starts again as if it had never been interrupted .
4. Synchronous asynchronous
Synchronous and asynchronous : Describes how the task is submitted .
Sync : After the task is submitted , Wait in place for the return result of the task , Don't do anything while waiting .
asynchronous : After the task is submitted , Don't wait for the returned result , To do something else , The return result of the task will be automatically processed by an asynchronous callback mechanism .
5. Blocking non blocking
Blocking non blocking : Describe the running state of the program .
Blocking : Before the call result returns , The current thread will be suspended , Only after the result is obtained will it return ( Blocking state ).
Non blocking : Before you can't get the results immediately , Go straight back to .( The ready state , Running state ).
ps:
Combination of appeal concepts : The most efficient combination : Asynchronous non-blocking .
Ideal state : The code written is always switched between ready state and running state , Difficult to achieve .
6. Process creation
Hardware requires operating system management , As long as there is an operating system, there is the concept of process .
New processes are created by an existing process .
Subprocesses : A process created by a process .
The parent process : The process that created the new process .
windows The lower parent process creates child processes with different address spaces ,( Multichannel technology requires the physical layer to realize the memory isolation between processes ), Any modification of a process in its address space will not affect another process .
7. Zombies and orphans
Zombie process : When you start a child process , The occupied process number will not be released immediately after the process ends .
The parent process needs to be able to view the basic information of its child processes , The amount of pid No. running time, etc .
All processes will enter the zombie process , Wait for the parent process to view .
The parent process does not die and creates child processes infinitely , And the subprocess will not end .
Orphan process : Child processes survive , The parent process died unexpectedly , The operating system will start a management program , Manage orphan processes and recycle related resources .
8. Termination of process
1. The normal exit ( Exit after the normal execution of the program , Or execute the end command of the program ).
2. Error exit ( The execution file does not exist )
3. Serious mistakes ( Execution of illegal orders , Reference does not exist , Be able to catch exceptions ).
4. Forced to end by other processes .
9. Process scheduling
Process scheduling : Long and short assignments are cpu The division of .
First come first serve scheduling algorithm : Good for long work , It's useless to work too often ,
Short job first algorithm : It's good for short work , Long homework is useless .
Time slice rotation + Multistage feedback queue :
Time slice : Divide the fixed time into N Multipoint , Each copy represents a time slice .
Set the multi-level ready queue , Queue priority at all levels from high to low , Time slice is divided from small to large .
The new process first enters the first level queue , Waiting in line to be allocated time slice .
If you run out of time , The process is not over , Then the process enters the end of the next level queue .
边栏推荐
- BUUCTF
- BOC protected alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC supplied by Qiyu
- Xctf attack and defense world crypto master advanced area olddriver
- Summary of 90 day learning materials and notes of Zhang Fei's actual electronic hardware engineer
- Day11 ---- 我的页面, 用户信息获取修改与频道接口
- Chapter 1: drinking soft drinks, step tariff calculation, step tariff calculation function, personal income tax, solving square root inequality, simplifying solving square root inequality, solving dem
- Zhang Fei hardware 90 day learning notes - personal record of day 3, please see my personal profile / homepage for the complete
- BOC protected tryptophan zinc porphyrin (Zn · TAPP Trp BOC) / copper porphyrin (Cu · TAPP Trp BOC) / cobalt porphyrin (cobalt · TAPP Trp BOC) / iron porphyrin (Fe · TAPP Trp BOC) / Qiyue supply
- About unregistered transfer login page
- Nacos usage of micro services
猜你喜欢
10 smart contract developer tools that miss and lose
Chapter 1: drinking soft drinks, step tariff calculation, step tariff calculation function, personal income tax, solving square root inequality, simplifying solving square root inequality, solving dem
Xctf attack and defense world crypto master advanced area olddriver
第一章:三位阶乘和数,图形点扫描
Detailed and not wordy. Share the win10 tutorial of computer reinstallation system
IP address is such an important knowledge that it's useless to listen to a younger student?
Common text labels
Chapter 2: find the classical solution of the maximum Convention and the least common multiple of a and B, find the conventional solution of the maximum Convention and the least common multiple of a a
CMD implements the language conversion of locale non Unicode programs
04 -- QT OpenGL two sets of shaders draw two triangles
随机推荐
Chapter 1: extend the same code decimal sum s (D, n)
Ae/pr/fcpx super visual effects plug-in package fxfactory
Explore the internal mechanism of modern browsers (I) (original translation)
Vscode reports an error according to the go plug-in go get connectex: a connection attempt failed because the connected party did not pro
Initialization and instantiation
Chapter 1: find the algebraic sum of odd factors, find the same decimal sum s (D, n), simplify the same code decimal sum s (D, n), expand the same code decimal sum s (D, n)
Geek Daily: the system of monitoring employees' turnover intention has been deeply convinced off the shelves; The meta universe app of wechat and QQ was actively removed from the shelves; IntelliJ pla
Native table - scroll - merge function
Zhang Fei hardware 90 day learning notes - personal record of day 3, please see my personal profile / homepage for the complete
unittest框架基本使用
Day11 ---- 我的页面, 用户信息获取修改与频道接口
4. Data binding
3. Data binding
BOC protected tryptophan zinc porphyrin (Zn · TAPP Trp BOC) / copper porphyrin (Cu · TAPP Trp BOC) / cobalt porphyrin (cobalt · TAPP Trp BOC) / iron porphyrin (Fe · TAPP Trp BOC) / Qiyue supply
Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
QT -- qfileinfo file information reading
Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
第二十章:y= sin(x)/x,漫步坐标系计算,y= sin(x)/x 带廓幅图形,奥运五环,小球滚动与弹跳,流水显示,矩形优化裁剪,r个皇后全控nxn棋盘
Chapter 2: find the number of daffodils based on decomposition, find the number of daffodils based on combination, find the conformal number in [x, y], explore the n-bit conformal number, recursively