Demo of producer and consumer Application

Source: Internet
Author: User

Demo of producer and consumer Application

Previous articles <. the correct way to open the blocking queue BlockingCollection in. NET> <two things about concurrent processing of applications in project development> from the perspective of code and theory, fully utilizes the attribute IsComplete and CompleteAdding of BlockingCollection provided by Microsoft to complete the concurrent design. This time, we will Design Concurrency from a streamlined producer consumer alone. For more information about the demo, see <. net parallel programming-4. implement High-Performance asynchronous queue >><. net parallel programming-7. high-performance asynchronous Queue Based on BlockingCollection>. For the code design logic, see:

Figure 1 shows the concurrency mode of the blocked queue, and Figure 2 shows the concurrency mode of the asynchronous queue.

According to the code above, the implementation logic of asynchronous queues is different from the implementation logic of blocking queues, but in fact, asynchronous queues are consumed by multiple consumers, in recursion, tasks are constantly called to open new threads, and the number of consumer threads depends on the number of queues. This is not very good. Of course we can make some improvements, blocking queues are consumed by a single consumer. We can easily change to multiple consumers. In general, this design is still very good. Take a note and study it later. It will be used directly in the project and the next spring moves!

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.