To download NI software, including the products shown below, visit ni.com/downloads.
Overview
Demonstrate the working principles of Producer-Consumer loop.
Description
The Producer-Consumer design architecture is very good for being able to send data between parallel processes, without sacrificing CPU usage when used with an event structure in the producer loop. The only issue which arises is if one tries to send data backup from the consumer to the producer. If this is attempted using another Queue, you will quickly find that both loops are at a deadlock, since Dequeue Element is a blocking function, and if you try to circumvent this with a timeout on the function, you are essentially back to polling. The attached ProducerConsumer_SendDataToProducer.vi demonstrates how to communicate data from the producer to the consumer using User Events. When data is sent from the producer to the consumer, the consumer loop immediately generates a user event and sends the same data right back to the producer loop.
Requirements
Software:
Steps to Implement or Execute Code
1. Run the VI.
2. Enter data into "element in" and press "Enqueue Element" button.
Additional Information or Resources
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.