当前位置:网站首页>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 .
边栏推荐
- Nature综述:微生物群落形成过程中的优先效应
- ELK日志分析系统安装和部署
- 2022/7/24-7/25
- Zabbix4.0 uses SNMP agent to monitor vcenter6.5
- urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: un
- 新技术引领大中型企业营销新变革,用友BIP CRM重磅发布!
- Helm chart explanation and common commands: helm template / package / plugin
- Security-001
- Xu Jinbo: AI protein prediction and design
- 你的列表很卡?这4个优化能让你的列表丝般顺滑
猜你喜欢

【数字识别】基于知识库实现手写体数字识别附matlab代码

Application skills of AWS dynamodb
![[image detection] realize the detection of nostrils and pupil circles based on combined separation filter matlab source code](/img/6a/92ace81b798810299a2fec0ce6ae70.png)
[image detection] realize the detection of nostrils and pupil circles based on combined separation filter matlab source code

【图像检测】基于Combined Separability Filter实现鼻孔和瞳孔等圆检测matlab源码

Implicit indicators for evaluating the advantages and disadvantages of automated testing

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

CaEGCN: Cross-Attention Fusion based Enhanced Graph Convolutional Network for Clustering 2021

NDK series (6): let's talk about the way and time to register JNI functions

真的很难理解?RecyclerView 缓存机制到底是几级缓存?

iMeta | 国际标准刊号ISSN印刷版正式确认,双ISSN申请完成
随机推荐
一位软件投资者的独白:我为什么不追逐快速增长的公司
简单实用的数据可视化案例
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: un
How to use xshell Free Edition
Simple and practical data visualization cases
Apple releases new iPhone se: equipped with A13 bionic processor, priced from 3299 yuan
Implicit indicators for evaluating the advantages and disadvantages of automated testing
Nature综述:微生物群落形成过程中的优先效应
股价暴涨180.46%!国产大硅片龙头沪硅产业上市:近4年净利累计不足6000万
Calling dht11/22 temperature and humidity sensor in Proteus simulation Arduino
强化学习——PyTorch 实现 Advantage Actor-Critic (A2C)
Pentium fast system call learning
What are the advantages of Tita's OKR system over other similar products or shared documents?
Bi Shi - University Logistics Management System Based on SSM
sort排序
Sudden, wechat important notice
Disable caching with meta HTML tags in all browsers
Pro multi store version system, versatile is it!
图基本知识代码
Flink怎么使用Savepoint