Operating System-Process Synchronization

Source: Internet
Author: User

1.1 Process Synchronization Mechanism

(1) atomic operation: the so-called atomic operation means that the operation will never be interrupted by any other task or event before execution is completed. That is to say, it is the smallest execution unit, it is impossible to have a smaller execution unit than it. Atomic operations require hardware support, so they are architecture-related.

(2) semaphores: The semaphores SEM is an integer. When its value is greater than 0, it indicates the number of currently available resources. When its value is smaller than 0, the absolute value indicates the number of processes waiting to use the resource. Note that the semaphore value can only be changed by the PV operation.

P (S) :( 1) subtract 1 from the semaphore s value, that is, S = S-1 (2) if S> = 0, the process continues to run; otherwise, the process is set to the waiting status and is discharged into the waiting queue.

V (s): (1) Add 1 to the semaphore s value, that is, S = S + 1; (2) if S> 0, the process continues to run; otherwise, release the first process in the queue waiting for the semaphore.

(3) spin lock: a spin lock can only be held by one kernel task at most. If a kernel task tries to request an already held spin lock, then the task will keep repeating-Rotating-waiting for the lock to be available again. The spin lock is mainly used in the kernel to prevent concurrent access to the critical zone in the multi-processor and to prevent competition caused by kernel preemption. No matter whether it is a mutex lock or a spin lock, there can be at most one lock at any time. That is to say, at most one execution unit can get the lock at any time. However, the two have slightly different Scheduling Mechanisms. For mutex lock, if the resource is occupied, the resource applicant can only go to sleep. But the spin lock will not cause the caller to sleep. If the spin lock has been maintained by another execution unit, the caller will keep repeating there to see if the lock holder has released the lock, this is why the word "Spin" is named.

(4) management process: the data structure of shared resources and all operations that can be performed on shared variables are concentrated in one module. Only one process is allowed to access resources in the management process at a time. A process waits for a queue, and waits for and wakes up operations. A queue is called a conditional queue. When a process that enters the management process cannot continue to run due to resource occupation or other reasons, the process enters the condition queue and releases the management process mutex. When another process of a management process releases resources related to a condition variable, it wakes up a process waiting on the condition.

(5) Convergence: A process can have many portals. One portal corresponds to a program, and one process can call the portal of another process. When a process calls another process entry and the called process is ready to accept the call, this will happen. When the caller sends a call request and the called process is not ready to accept the call, the caller waits. Otherwise, when the caller is ready to accept the call, the caller waits. That is, first arrive at the Union and wait for the latter to arrive. When multiple processes call the same entry of the same process, the caller accepts the call in the order of first-come first-served (FCFS. Call parameters and return parameters can be carried at the entrance to exchange information. The caller can select the entrance to join.

(6) Distributed System

1.2 thread synchronization mechanism

(1) Event: an event has two States: the excitation state and the unfired state. It is also known as having a signal or having no signal. There are two types of events: manual event resetting and automatic event resetting. After the manual reset event is set to the excitation state, it will wake up all the waiting threads and remain in the excitation state until the program re-sets it to the unfired state. When an automatic reset event is set to the excitation status, it will wake up the "one" Waiting thread and automatically restore it to the unfired status.

(2) critical section: the multi-threaded serialization is used to access public resources or a piece of code, which is fast and suitable for controlling data access. Only one thread is allowed to access Shared resources at any time. If multiple threads attempt to access public resources, after one thread enters, other threads trying to access public resources will be suspended until the threads entering the critical section exit. After the critical section is released, other threads can be preemptible.

(3) mutex: uses the mutex object mechanism. Only threads with mutex objects have the permission to access public resources. Because there is only one mutex object, it can ensure that public resources are not simultaneously accessed by multiple threads. Mutual exclusion can not only achieve the security sharing of public resources for the same application, but also the security sharing of public resources for different applications.

(4) semaphore: it allows multiple threads to access the same resource at the same time, but it must limit the maximum number of threads that can access the resource at the same time.

Operating System-Process Synchronization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.