7. Critical area of process synchronization

Source: Internet
Author: User

A solution to the problem of producer-consumer

Atomic Operation (Atomic operation) requires that the operation be completed one time, without interruption in the middle

Race Condition : The situation where several processes access and manipulate shared data concurrently (concurrency). The final value of the shared data depends upon which process finished last; (who finishes)

In order to avoid race conditions, concurrency must be synchronized

Critical area problem (the critical-section problem)

    • Suppose n processes compete to access shared data
    • Each process has a piece of code, called a critical section , where the process accesses shared data through this code.
    • Other code does not have access to shared data
    • In these n processes, there are at least 1 processes or even modified shared data

How do you ensure that when a process I is executing in its own critical section, no other process J is also executing in its critical section?

Solutions to critical zone problems must meet 3 conditions

  mutually exclusive conditions ( only a limited number of processes are in the critical section)

  Idle let in:

If

No process is in its critical section and some processes request access to its critical section

Then

      only those processes that are not remainder sections can participate in the selection of critical areas and This election is not allowed indefinitely ( Indefinitely) delayed (limited entry to critical section)

  Limited wait

An upper bound of the number of times a process has entered their critical section, from its request to the time it is allowed to enter the critical section

Assuming that the process is executing on its own

does not consider the relative execution speed between n processes

Algorithm 1

Define two processes to share data

int turn;

and take the initial value turn=0;

turn=i; process Pi can enter the critical section

Process Pi

do{

while (trun!=i)

Critical section//wait

Turn=j;

Remainder.section//Return

}while (1);

Hardware instruction solution for critical area problem

The idea is that only when lock is false can we go in or wait

7. Critical area of 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.