当前位置:网站首页>What are the methods of process synchronization?
What are the methods of process synchronization?
2022-07-27 23:36:00 【Hua Weiyun】
What are the ways of process synchronization ?
A critical region
The critical area is a piece of code , Within a critical region, processes will access critical resources . At most one process can enter the critical region at any time , in other words , The critical region is exclusive . therefore , For mutual exclusive access to critical resources , Before each process enters the critical area , It needs to be checked first .
The mutex
Is to use a mutually exclusive variable to directly restrict multiple processes , Each process has access to public resources only if it has this variable , Because there is only one mutex , So it can ensure the correct access to resources .
Semaphore
Semaphore (Semaphore) It's an integer variable , You can perform auto increment and auto decrement operations on it , Auto subtraction is also known as P operation , Auto increment operation is also called V operation . These two operations need to be designed as primitives , It's indivisible , The usual way to do this is to mask interrupts . Processes use these two operations to synchronize .
about P operation , If the semaphore is less than 0, Then the process performing the operation will block , Otherwise, continue to execute ;
about V operation , If the semaphore after operation is less than or equal to 0, Then it wakes a process from the blocking queue .
Tube side
Management uses object-oriented ideas , It will represent the data structure of the shared resource and related operations , Including synchronization mechanism , It's all concentrated and packaged together . All processes can only access critical resources indirectly through the pipe , The tube only allows one process to enter and perform operations , To achieve mutual exclusion of processes . Multiple condition variables are set in the tube , Indicates the condition under which multiple processes are blocked or suspended . Execute... On conditional variables wait() Operation will cause the calling process to block , Let the process out to another process to hold .signal() Operations are used to wake up blocked processes . The tube has an important feature , That is, only one process can use the tube at a time . The process can't always occupy the pipe when it can't continue to execute , Otherwise, other processes will never be able to use pipelining .
What are the ways of interprocess communication ?
The Conduit
The pipe is half duplex , Data can only flow in one direction ; If communication between the two parties is needed , Two pipes need to be built .
Pipes can only be used between parent-child processes or sibling processes, or processes with kinship ;
A pipe is a process at both ends of a pipe , It's a document , But it's not a normal document , It doesn't belong to some kind of file system , It only exists in memory .
The essence of the pipeline is a kernel buffer , The process accesses data from the buffer in a first in, first out fashion , The process at one end of the pipeline writes data to the buffer in sequence , The process at the other end reads the data in sequence . This buffer can be seen as a circular queue , The positions of reading and writing are automatically increasing , Can't change at will , A data can only be read once , After reading it out, the buffer no longer exists . When the buffer is empty or full , There are certain rules to control the corresponding read process or write process to enter the waiting queue , When the empty buffer has new data written or the full buffer has data read out , Just wake up and wait for the process in the queue to continue reading and writing .
The main limitation of pipeline lies in its characteristics , For example, only one-way data flow is supported , Can only be used between related processes , Isn't there a name , The buffer of the pipeline is limited and so on .
name pipes
This kind of pipe is also called FIFO. Naming pipes is different from pipes , It provides a pathname associated with it , Exists in the file system as a named pipe file , such , Even if the process is not related to the creation process of the named pipe , As long as you can access this path in the file system , You can communicate with each other through named pipes . Named pipes strictly follow the first in first out principle , It does not support data random location . The name of the named pipe exists in the file system , But the content is stored in memory .
Message queue
The message queue is a linked list of messages , Have a specific format , It's stored in memory , And each message queue has a unique identifier . Message queuing allows one or more processes to write and read messages to it , therefore , Using message queues , A process can send a block of data to another process , Each chunk has a type , The receiving process can independently receive data structures with different types , This process is asynchronous , We can avoid synchronization and blocking of named pipes by sending messages . But there is a limit to the size of the data block of the message queue .
边栏推荐
- 初步了解Panda3D音频和高级交互组件
- 习题 --- BFS
- Application skills of AWS dynamodb
- 解决5G使用痛点,魅族17 mSmart 5G快省稳技术发布
- Nature review: preferential effects in the formation of microbial communities
- Pentium fast system call learning
- 总投资600亿!富士康半导体高端封测项目正式落户青岛
- 怎么使用C# Winform实现复制文件显示进度
- 股价暴涨180.46%!国产大硅片龙头沪硅产业上市:近4年净利累计不足6000万
- Sudden, wechat important notice
猜你喜欢

西门子PLC能否实时无线采集多处从站模拟量数据?

Flink怎么使用Savepoint

常用泰勒展开

深入了解 XXE 注射

My annual salary is 1million, and I don't have clothes more than 100 yuan all over my body: saving money is the top self-discipline

Implicit indicators for evaluating the advantages and disadvantages of automated testing
![[number recognition] recognize 0-9 numbers based on Hopfield neural network with matlab code](/img/10/de712b67a7538be03f8fb722271949.png)
[number recognition] recognize 0-9 numbers based on Hopfield neural network with matlab code

WWW 2019 | HAN:异质图注意力网络

Desai wisdom number - other charts (parallel coordinate chart): family's willingness to allocate assets in the future

Bi Shi - University Logistics Management System Based on SSM
随机推荐
Test article
[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code
2022/7/26
【ELM分类】基于核极限学习机和极限学习机实现UCI数据集分类附matlab代码
iMeta | 国际标准刊号ISSN印刷版正式确认,双ISSN申请完成
三次握手的Socket交互流程
【信号去噪】基于卡尔曼滤波实现信号去噪附matlab代码
Apple releases new iPhone se: equipped with A13 bionic processor, priced from 3299 yuan
Excel VBA finds out the maximum and minimum values of a column of time, and repeatedly pastes multiple values according to the actual situation
采用汇顶屏下光学指纹方案,三星Galaxy A71 5G上市
reduce错误示范
迪赛智慧数——其他图表(平行坐标图):家庭未来资产配置意愿
Kubevera deploys applications through cli
C#委托用法--控制台项目,通过委托实现事件
四次挥手的Socket交互流程
携手长江存储,江波龙推出全球最小扩展卡
VIM editor tutorial
强化学习——PyTorch 实现 Advantage Actor-Critic (A2C)
请求合并哪家强——接口请求合并的3种技巧,性能直接爆表
Pentium fast system call learning