Producer-Consumer issues

Source: Internet
Author: User

With the synchronization and mutual exclusion between the previous processes, producer-consumer issues are often used to resolve synchronization and mutex issues during multi-process concurrent execution.

The principle is as follows:

associate a bounded buffer of length n (n>0) with a group of producer processes P1,p2,..., pm and a group of consumer processes c1,c2,..., CK, as long as the buffer is not full, the producer can put the product into the buffer, as long as the buffer is not empty, Consumers will be able to take away product consumption from it.

(1) Synchronization conditions: Producers only at least one critical section of the unit is empty, in order to produce products, consumers only at least one critical area is filled in the product, in order to consume the product, so set two synchronization variables, avail for the producer of private variables, the initial value of N, Full is the consumer's private variable, with an initial value of 0.

(2) Mutually exclusive condition: the producer and the consumer cannot access the critical resource at the same time, so set a mutex variable to the initial value of 1.

Producer Process: Consumer processes:

P (Avail) p (full)

P (Mutex) p (mutex)

Generate a product to consume a product

V (full) v (avail)

V (Mutex) v (mutex)

Producer-Consumer issues

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.