Showing results for 
Search instead for 
Did you mean: 

producer consumer design pattern



I am trying to build a simple program that does the following:

1. when program starts, the indicator is initialized to -999

2. when Measure button is clicked, the indicator shows random number continuously.

3. when Save button is clicked, the indicator shows 1

I use the event-based producer-consumer design pattern and it works great. However, I cannot find a way to allow the CONTINUOUSLY generating of random number when Measure is clicked. Can someone shed a light on it? Thanks a lot for the help. 



0 Kudos
Message 1 of 4

One simple way to do it is to use the Timeout event case. You can modify the timeout value based on what events have occurred. See attached mod.


Not saying this is the best way. Kind of depends on where the program goes from here. 

0 Kudos
Message 2 of 4

In the consumer loop have it operate as a state machine.  Put the next state on a shift register.  Put a timeout on the Dequeue function.


1. Start the state machine with the state shift register initialized to the "Initialize" state.

2. If the Dequeue function times out, then the state is the same as the previous state

else the state is the state from the Command List.

3. Any state, such as the Save state, could set the next state to some thing else (like "Measure").



0 Kudos
Message 3 of 4
Thank you all.
0 Kudos
Message 4 of 4