Synchronization and mutual exclusion of processes (software methods)

Source: Internet
Author: User

what is synchronization. What is mutual exclusion. <?xml:namespace prefix = o ns = "Urn:schemas-microsoft-com:office:office"/>

Mutex: Refers to a resource that allows only one visitor to access it, with uniqueness and exclusion. However, mutual exclusion cannot limit the order in which visitors access resources, that is, access is unordered.

Synchronization: Refers to the mutual exclusion of the basis (in most cases), through other mechanisms to achieve the visitor's orderly access to resources. In most cases, synchronization has been mutually exclusive, especially if all writes to the resource must be mutually exclusive. In rare cases, multiple visitors can be allowed to access resources at the same time.

one of the mutually exclusive and synchronous workarounds: ( software method)

There are many kinds of software solutions, and more representative software methods are proposed by the Dutch mathematician Dekker

Dekker algorithm and the Peterson algorithm proposed by scientists G.l.peterson.

Initial Assumptions:

In order to control the mutual exclusion of two processes into a critical section, two processes can be rotated into the critical section. Specifies the process number.

var turn 0..1

P0 P1

....                                                  ....

While turn <> 0 does {nothing} and turn <> 1 do

{Nothing} {Nothing}

< critical area >; < critical area >;

Turn:=1; turn:=0;

.....                                               .....

Existing problem Analysis:

Issue 1: "Busy waiting" phenomenon consumes many resources of the machine. The while statement loops through the process time slice.

Issue 2: The process is strictly alternating into the critical section. If a process needs to use a critical section multiple times, a process with a low critical section frequency severely restricts the degree of execution of processes with high critical zone frequencies. After all, turn does not indicate whether the critical section is occupied.

Issue 3: Any process fails within or outside the critical section, and other processes may not be able to move forward because they wait for the critical section to be used.

first-time improvements:

Analysis: The primary idea of the main problem is that there is no target for the critical region, but the strict process of alternating execution. You can set a status flag for a critical section to indicate whether the critical section is available. When a critical section is idle, any process enters. However, the critical section flag must be modified to be "occupied" and other processes cannot enter the critical section. When the critical section is used, the flag must be modified to be "idle". This eliminates the need to make the processes strictly alternate with critical sections, and if a process fails outside the critical section, it will not affect other processes. The algorithm is described as follows:

 

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.