11-02-2012 02:42 PM
Brandyn,
Isn't a state machine still considered polling? I guess I don't see the difference between the way I have it written now and the State Machine idea.
I've used your ideas in the updated code.
11-02-2012 02:48 PM
State Machines inherently arnt polling, its the action of continuously having your while loop iterate that makes something polling. Notice on your dequeue function you do not have a timeout wired. The default is -1 which means it will sit and wait until it has something to dequeue. Implementing a state machine in the consumer loop will provide a lot more flexibility and scalability.
Im curious. In the updated code, whats the purpose of the while loop with the queue status function?
11-02-2012 02:58 PM
That one was a suggestion from crossrulz on Message #11. Basically, instead of looking at the elements in the queue each time the consumer loop made a pass, his idea (how I interperted it) was to just move it down to the other while loop to see how many items were left. When it's zero, it jumps out of the While Loop, releases the queue (and errors out the dequeue element) and closes out.
I'll take a stab at the state machine idea. Thanks for all of your suggestions.
Eric
11-02-2012 03:03 PM
Ahhhhhh....yes, sorry normally Im used to having the producer on top and consumer on the bottom. Please excuse the brain fart. But when I have time later tonite, I will show you what I mean about having a state machine in the consumer loop.
11-02-2012 03:23 PM - edited 11-02-2012 03:24 PM
@Eric1977 wrote:
That one was a suggestion from crossrulz on Message #11. Basically, instead of looking at the elements in the queue each time the consumer loop made a pass, his idea (how I interperted it) was to just move it down to the other while loop to see how many items were left. When it's zero, it jumps out of the While Loop, releases the queue (and errors out the dequeue element) and closes out.
I'll take a stab at the state machine idea. Thanks for all of your suggestions.
Eric
While this works it is a sketchy architecture at best and once again turns the system into a polling system. I hate to harp on it and crossrulz will probably call me out on it but explicit control of the system is a more robust architecture. Granted, most of the stuff I work on are fairly large system and require the extra complexity just to get a maintainable system but I have learned over the years that even small projects can end up growing and take on a life of their own. Adopting good practices in any code you develop makes expansion and maintenance much easier. Also, if you think things through a bit and consider reuse from day one you end up developing some nice libraries over time as well as common approaches to things. Each system you develop becomes easier to implement because you are building upon proven techniques and code.
11-02-2012 03:54 PM
I havne't looked at the code, but to ensure that the queue is finished before exiting; Stop button should enqueue a Stop command and exit it's producer loop. Thus the consumer will consume all commands until it encounters Stop and exits and destroys the queue.
/Y
11-02-2012 07:17 PM
@Mark_Yedinak wrote:
I hate to harp on it and crossrulz will probably call me out on it...
Actually, I'm in full agreement with you Mark. I just made that suggestion just as an option.
11-02-2012 07:49 PM
@Brandyn wrote:
Ahhhhhh....yes, sorry normally Im used to having the producer on top and consumer on the bottom. Please excuse the brain fart. But when I have time later tonite, I will show you what I mean about having a state machine in the consumer loop.
I look forward to it. ![]()
11-03-2012 03:23 PM
Eric,
I apologize I was not able to get to it last night. I will try my best to get it up between tonite or tomorrow.
11-05-2012 06:57 AM
That is quite alright. I was off for the weekend.