07-22-2014 04:24 AM
hI
I'am developing a vi in which i use a producer consumer design pattern.
the producer enqueue's the states for the consumer. but at some point of excecution i wish to enqueue the next state of the consumer statemachine, from within the consumer state itself. does this cause any problem??.
in other words can i enqueue data within the consumer loop also. so thet the next state of consumer will depend on the data enqueued
Thanks
Solved! Go to Solution.
07-22-2014 04:41 AM
Hey,
this is no problem you can enqueue the states from both loops (or even a third.....)
Regards,
CMW..
07-22-2014 04:42 AM
Yes this approch may cause some unexpected order of execution.
you should use only producer loop to send commands to consumer loop.
make consumer loop as simple state machine.
If you want to trigger other state which can occur in consumer ,use user events to send command from consumer to producer , and producer in return will give you next state.
07-22-2014 04:45 AM
The problem is when in a single queue you start enqueuing from multiple places then next queue element out depends on timing when they got inserted.
so somtimes it may have different order of execution than expected.
07-22-2014 04:46 AM
A queued state machine consumer will act as a synchronous process if there is one 'sender', and an asynchronous process if there are many 'senders'. If you are worried about unexpected states, then maybe you could split your QSM into two? It depends on what you are doing, of course.
07-22-2014 05:04 AM
Of course it depends on application , still i am talking about one definite entry point for individual queue.
So that the next state dequeued will be know to user already.
07-22-2014 05:15 AM - edited 07-22-2014 05:16 AM
Neos, it doesn't always matter when a message gets processed. A QSM pattern is an implementation of an Actor pattern, in which a message gets sent from one or many origins, knowing that - at some point - it will be processed. If you want anything to be determinate, then you would want to use another structure, maybe a timed while loop.
07-22-2014 05:27 AM
Actually let me be clear, what i am saying is if user has a pattern where he is send commands from producer to consumer using a queue , in consumer case states are being dequed and processed , after that in consumer loop only we are enqueing next state.
so basically now in queue 2 entry points are there.
suppose consumer has states A, B, C, D in which A is executing right now at the end of its completion it enques another state B.
But at the same time user has pressed a button on the front panel which wants to execute state C.
at this point somtimes order of execution can be A, B, C or A. C, B.
I have not worked on Actor framework till now , so have a very less idea about it.
07-22-2014 05:48 AM
Thank you all for the suggestions.
07-22-2014 09:44 AM - edited 07-22-2014 09:47 AM
I make extensive use of Queued Message Handleres where both the "Producer" and consumer enqueue to the same queue.
A "Firinstance" from work today: here are two captures of a part of the same code
The top loop controls the State of a semi autonomous process where data is gathered.
The thing to remember is to use a priority queue. Enqueue to self and flush as appropriate, enqueue opposite end from the controler. See also "A Trip To Grandma's House"
It is a very powerful technique for large applications where you want to abstract out the "what" and "When" from the how and just let a loop "Do"
And Yes, If I had chosen a unrestricted datatype (string, var) rather than an enum and built the lower loop as a child class you have an "Actor"