Process Synchronization and Asynchronization-software implementation (algorithm)

Source: Internet
Author: User

I. Preliminary ideas

Let the two processes achieve synchronization and mutex access to critical resources.

Pseudocode:

Turn .. 0 1p0while turn = 1 do {nothing} <critical section> turn: = 1p1while turn = 0 do {nothing} <critical section> turn: = 1

Problem:

When the value of turn is 0, The P0 process is before entering the critical section (outside the critical section). If a failure occurs, the execution of other processes will be affected. Similarly, when turn is 1, process P1 also affects the execution of process P0.

In addition, if another process fails in the critical section, the value of turn cannot be changed, and execution of other processes may be affected.

In short, the execution of other processes is affected regardless of whether the process is in or out of the critical section. In addition, they must be staggered for execution.

First improvement:

"Preliminary assumptions": Let's leave a question, as mentioned above. The reason is that the execution of one process depends on the execution of another process. To solve the problems left over from the preliminary idea, we use a flag to indicate whether the critical zone is in occupied state.

When flat [0] and flat [1] are true, they indicate P0 and P1 respectively. When they are false, they indicate P0 and P1 do not occupy the critical section. I personally define this idea as "array method" and "array method" for my understanding. (Of course there may be other better names ).

I have to mention that when I was learning Linux,

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.