当前位置:网站首页>How to use information mechanism to realize process mutual exclusion, process synchronization and precursor relationship
How to use information mechanism to realize process mutual exclusion, process synchronization and precursor relationship
2022-07-06 08:00:00 【Computer Xiaobai passed by】
Before that, you can refer to this article 《 operating system 》- A preliminary understanding of semaphore mechanism Have a general understanding of the information base
Semaphore base realizes mutual exclusion of processes
There are several steps to realize the mutual exclusion of processes :
1、 Analyze the key activities of concurrent processes , Dividing critical zone ( Such as : Access to critical resource printers should be placed in the critical area )
2、 Set up Mutex semaphore mutex, The initial value is 0( Semaphore mutex Express “ Places to enter the critical zone ”)
3、 In the entry area P(mutex)—— Application resources
4、 In the exit area V(mutex)—— Release resources 

Be careful : Yes Different critical resources need Set different amounts of mutually exclusive information P、V Operations must appear in pairs . The lack of P Operation will result in critical resources not being mutually exclusive , The lack of V The operation will cause the resource to be accessed and cannot be released , The waiting process will never be awakened
The information mechanism realizes process synchronization
Process synchronization : Let the concurrent processes advance orderly as required
For example, in the implementation process 1 Must be better than process 2 First access critical resources , This process is called process synchronization when it is pushed forward according to certain requirements , Let the asynchronous and concurrent processes cooperate with each other 、 To advance in an orderly way
Realizing process synchronization can be divided into the following steps :
1、 Analyze where process synchronization is needed , must One before and one after Perform two operations ( Or two sentences of code )
2、 Set up Synchronous semaphore S, The initial value is 0
3、 stay “ Front operation ” After performing V(S)
4、 stay “ Post operation ” Before execution P(S)

understand
Semaphore S Represents a resource , At first, there was no such resource .P2 To use this resource will be locked in P(S) Operate here , until P1 After execution V(S) take S The number of add 1 after P2 To be carried out .
If you execute to V(S) operation , be S++ after S=1. Then when the execution reaches P(S) In operation , because S=1, Indicates that there are available resources , Will execute S–,S The value of changes back to 0,P2 The process will not execute block The original language , Instead, continue to execute the code 4.
If you execute to P(S) operation , because S=0,S-- after S=-1, Indicates that no resources are available at this time , therefore P During the operation block The original language , Active request blocking . Then when the code is executed 2, Then execute V(S) operation , S++, send S Change back 0, Because there are processes in the blocking queue corresponding to the semaphore , So it will V In operation wakeup The original language , Wake up the P2 process . such P2 You can continue to execute Code 4 了
The information mechanism realizes the precursor relationship
What is the implementation of precursor relationships, for example
example : process P1 There is a code in S1,P2 There is a code in S2 ,P3 There is a code in S3 …… P6 There is a code in S6. These codes are required to be executed in the order shown in the following precursor diagram :
In fact, each pair of precursor relationships is a process synchronization relationship ( We need to ensure that one before another ), Therefore, the implementation of precursor relationship can be divided into the following steps :
1、 want Set a synchronization amount for each pair of precursor relationships
2、 stay “ Front operation ” Then execute the corresponding synchronization information V operation
3、 stay “ Post operation ” Previously, execute the corresponding synchronization information P operation
Content review :
边栏推荐
- 数据治理:微服务架构下的数据治理
- Go learning notes (3) basic types and statements (2)
- matplotlib. Widgets are easy to use
- Position() function in XPath uses
- [非线性控制理论]9_非线性控制理论串讲
- Hill sort c language
- Inspiration from the recruitment of bioinformatics analysts in the Department of laboratory medicine, Zhujiang Hospital, Southern Medical University
- Easy to use tcp-udp_ Debug tool download and use
- MEX有关的学习
- Data governance: metadata management
猜你喜欢
![[count] [combined number] value series](/img/f5/6fadb8f1c8b75ddf5994c2c43feaa6.jpg)
[count] [combined number] value series

"Designer universe" APEC design +: the list of winners of the Paris Design Award in France was recently announced. The winners of "Changsha world center Damei mansion" were awarded by the national eco
![[factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems](/img/6d/282d904810807810adb06b071fb39b.jpg)
[factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems

IP lab, the first weekly recheck

22. Empty the table

Opencv learning notes 8 -- answer sheet recognition

Asia Pacific Financial Media | "APEC industry +" Western Silicon Valley invests 2trillion yuan in Chengdu Chongqing economic circle to catch up with Shanghai | stable strategy industry fund observatio

Make learning pointer easier (3)
![[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map](/img/c3/1b6013bfb2441219bf621c3f0726ea.jpg)
[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map

Asia Pacific Financial Media | female pattern ladyvision: forced the hotel to upgrade security. The drunk woman died in the guest room, and the hotel was sentenced not to pay compensation | APEC secur
随机推荐
(lightoj - 1410) consistent verbs (thinking)
Asia Pacific Financial Media | designer universe | Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers
Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist
数据治理:元数据管理篇
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
【Redis】NoSQL数据库和redis简介
软件开发的一点随记
49. Sound card driven article collection
National economic information center "APEC industry +": economic data released at the night of the Spring Festival | observation of stable strategy industry fund
Redis list detailed explanation of character types yyds dry goods inventory
[count] [combined number] value series
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
CAD ARX gets the current viewport settings
Get the path of edge browser
Inspiration from the recruitment of bioinformatics analysts in the Department of laboratory medicine, Zhujiang Hospital, Southern Medical University
opencv学习笔记八--答题卡识别
Database addition, deletion, modification and query
Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
649. Dota2 Senate