流程同步 (Process Synchronization)
Process Synchronization means sharing system resources by processes in a such a way that, Concurrent access to shared data is handled thereby minimizing the chance of inconsistent data. Maintaining data consistency demands mechanisms to ensure synchronized execution of cooperating processes.
进程同步是指通过进程共享系统资源的方式,即可以处理对共享数据的并发访问,从而最大程度地减少数据不一致的机会。 维护数据一致性需要机制以确保协作过程的同步执行。
Process Synchronization was introduced to handle problems that arose while multiple process executions. Some of the problems are discussed below.
引入了流程同步来处理在执行多个流程时出现的问题。 下面讨论了一些问题。
临界区问题 (Critical Section Problem)
A Critical Section is a code segment that accesses shared variables and has to be executed as an atomic action. It means that in a group of cooperating processes, at a given point of time, only one process must be executing its critical section. If any other process also wants to execute its critical section, it must wait until the first one finishes.
关键部分是访问共享变量的代码段,必须作为原子动作执行。 这意味着在一组协作流程中,在给定的时间点,只有一个流程必须执行其关键部分。 如果任何其他进程也想要执行其关键部分,则必须等待直到第一个完成。
关键截面问题的解决方案 (Solution to Critical Section Problem)
A solution to the critical section problem must satisfy the following three conditions:
关键截面问题的解决方案必须满足以下三个条件:
1.互斥 (1. Mutual Exclusion)
Out of a group of cooperating processes, only one process can be in its critical section at a given point of time.
在一组协作过程中,在给定的时间点,关键过程中只能有一个过程。
2.进展 (2. Progress)
If no process is in its critical section, and if one or more threads want to execute their critical section then any one of these threads must be allowed to get into its critical section.
如果关键部分中没有进程,并且一个或多个线程要执行其关键部分,则必须允许这些线程中的任何一个进入其关键部分。
3.有限的等待 (3. Bounded Waiting)
After a process makes a request for getting into its critical section, there is a limit for how many other processes can get into their critical section, before this process's request is granted. So after the limit is reached, system must grant the process permission to get into its critical section.
流程提出进入其关键部分的请求后,在批准该流程的请求之前,有多少其他流程可以进入其关键部分受到限制。 因此,在达到限制后,系统必须授予流程权限才能进入其关键部分。
同步硬件 (Synchronization Hardware)
Many systems provide hardware support for critical section code. The critical section problem could be solved easily in a single-processor environment if we could disallow interrupts to occur while a shared variable or resource is being modified.
许多系统为关键节代码提供硬件支持。 如果我们可以禁止在修改共享变量或资源时发生中断,则可以在单处理器环境中轻松解决关键部分问题。
In this manner, we could be sure that the current sequence of instructions would be allowed to execute in order without pre-emption. Unfortunately, this solution is not feasible in a multiprocessor environment.
以这种方式,我们可以确定当前的指令序列将被允许按顺序执行而无需抢先。 不幸的是,该解决方案在多处理器环境中不可行。
Disabling interrupt on a multiprocessor environment can be time consuming as the message is passed to all the processors.
当消息传递到所有处理器时,在多处理器环境中禁用中断可能很耗时。
This message transmission lag, delays entry of threads into critical section and the system efficiency decreases.
此消息传输滞后会延迟线程进入关键部分的进入,从而降低系统效率。
互斥锁 (Mutex Locks)
As the synchronization hardware solution is not easy to implement for everyone, a strict software approach called Mutex Locks was introduced. In this approach, in the entry section of code, a LOCK is acquired over the critical resources modified and used inside critical section, and in the exit section that LOCK is released.
由于并非所有人都难以实现同步硬件解决方案,因此引入了一种称为Mutex Locks的严格软件方法。 在这种方法中,在代码的输入部分中,将在关键部分内部修改和使用的关键资源上获取LOCK,并在退出部分中释放LOCK。
As the resource is locked while a process executes its critical section hence no other process can access it.
由于资源在进程执行其关键部分时被锁定,因此其他进程无法访问它。
翻译自: https://www.studytonight.com/operating-system/process-synchronization