Operating System-solves time-related errors in Concurrent Processes

Source: Internet
Author: User

Operating System-solves time-related errors in Concurrent Processes

Many processes exist in a multi-channel programming system. They may mount the primary memory at the same time and wait for the scheduling of the processor, which forms a concurrent process. For a single-core processor, a concurrent process does not occupy the processor for simultaneous execution, but loads the master memory at the same time. When the process is executed, it depends on the scheduling policy of the process! When talking about concurrent processes, I think that the concurrency of processes will produce many errors, which should be avoided as much as possible when designing the system or writing software.

Why are errors caused by concurrent execution of processes? In the final analysis, concurrent processes access Shared variables. When multiple processes access Shared variables, they may encounter time-related errors or deadlocks.

I. Graph Analysis

2. Graph Analysis

Speaking of process access to shared resources, I think we should first clarify the problem of mutual exclusion between Process Synchronization and process.

1. Process mutex: when several processes need to use a shared resource, at any time, only one process can use shared resources, other processes to be used must wait to know that the resource owner has released the resource.

2. Process Synchronization: There is a constraint between concurrent processes. Execution of a process depends on messages of another process. When a process does not receive messages from another process, it should wait, the message is awakened only after it is reached.

3. Time-related errors: when multiple processes run together, shared variables are accessed alternately. However, when a process is interrupted due to its own reasons or external reasons, run the command later, causing an error in the running result.

For example:

A residential area has two doors, one of which is the entrance and the other is the exit. The count counter is used to display the number of people in the residential area. When someone enters, the count and increment are implemented by the process PIN. When someone exits, the process POUT is subtracted by one. The two processes are as follows:

 

begin     count: interge                                                                    count: =0cobeginprocess PIN      R1: integer;begin     R1:=count;     R1:=R1+1;     count: =R1;end ;process POUT      R2: integer;begin     R2:= count;     R2:=R2-1;     count:=R2;end;coend;end;
Assume that the count value is count = n at a time, and one person is about to enter, and one is about to go out at the same time, so both the process PIN and POUT must be executed at the same time, if the PIN and POUT processes are not interrupted, the count + 1 and count-1 Operations, count or n operations are completed respectively. If the PIN Operation is interrupted, see

 

After the execution, the result will be n + 1, which is an instance of time-related errors.

Solution: When PV is used, a term called critical section is introduced for PV operations. A critical section refers to the program segment related to shared variables in concurrent processes. The related critical section refers to the critical sections designed for the same variables in a concurrent process. The principle of the PV operation is to ensure that when a process is executed in the critical section, the other process is not allowed to enter the relevant critical section for execution. That is, the access of a process to shared variables is mutually exclusive, this will not cause time-related errors. For an example in the above table, after the process PIN is interrupted, POU cannot access the shared variable count until the PIN process ends, so that POUT can be accessed. The final result is correct.

Iii. Summary

The key to solving errors between concurrent processes is to solve the shared variable access mode. When multiple processes want to access Shared variables, we must manage the usage rules of each process, otherwise, the program will go wrong. The PV operation is used to allow mutually exclusive processes to run in their respective critical zones. This solves the time-related errors between concurrent processes.

Related Article

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.