Operating System: Process Synchronization

The main reference herein "computer operating system (fourth edition)" (Xi'an University of Electronic Science and Technology Publishing House) and Tsinghua operating system open class (to Yong, Yu Chen), finishing the basic concepts of the operating system for their own review inspection.

Process Synchronization

To ensure that multiple processes can run an orderly manner, multi-channel programming system introduced in the process of synchronization mechanisms. Common synchronization mechanism hardware synchronization mechanism, semaphore mechanism, the tube mechanism.

basic concepts

The main task is to process synchronization mechanism to coordinate the implementation of the order of a number of related processes, enabled according to certain rules sharing system resources between the execution of the program with a concurrent process reproducibility .

Relationrs

  1. Indirect constraints: the critical resource, the process can only be mutually exclusive access to such resources must be allocated by a unified system;
  2. Direct constraints: constraints direct cooperation from the process.

Critical resources (Critical Resource)

Allow only the use of a process called the critical resource resource (Critical Resource). Many physical devices are all critical resources such as input, printers and so on.

The critical area (Critical Section)

Access to critical resources in a process that code is called the critical zone. Access to critical resources recycling process can be described as follows:

while(true) {
    OnCriticalSectionEnter(); // 进入区代码,检查待访问资源,设置正在访问标志
    OnCriticalSection(); // 临界区代码
    OnCriticalSectionExit(); // 退出区代码,把标志位恢复为未被访问的状态
    DoOtherThings(); // 剩余区代码,不属于访问临界资源的范围
}

Synchronization rules

  1. Let requesting process immediately when critical resource is free to enter the critical section;
  2. Critical resources are requested to allow other processes waiting to access;
  3. Access to critical resources to the process should be guaranteed for a limited period of time to enter the critical section;
  4. When the process should not enter the critical region immediately release the processor.

Hardware synchronization mechanism

Many computers offer some special hardware instructions to solve the problem of critical areas, such as: disable interrupts, Test-and-Set instruction, Swap instruction.

Semaphore (Semaphore) Mechanism

Semaphore mechanism is a process synchronization tool proposed by the Netherlands scholars Dijkstra, it is currently the most widely used synchronization mechanism.

The tube mechanism

The tube will be appreciated that the mechanism of semaphore mechanism package, which contains the object-oriented thinking.

Guess you like

Origin www.cnblogs.com/Li-F/p/11872120.html