Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^3: How to create a two dimensional queue in Perl

by BrowserUk (Pope)
on Aug 05, 2013 at 17:52 UTC ( #1047940=note: print w/ replies, xml ) Need Help??

in reply to Re^2: How to create a two dimensional queue in Perl
in thread How to create a two dimensional queue in Perl

I want to write a state machine using queues Meaning :Each state has two or more operations After each operation is there that operation from the given state should be removed ;and only after all operations are done ,the state should be dequeued from the queuue and we should move forward to the next state

Let's visualise that:

[ state1: [ op1; op2; op3 ] ] [ state2: [ op1; op2; op3; op4 ] ] [ state3: [ op1; op2; op3; op4; op5; op6 ] ] [ state4: [ op1; op2; op3; op4; op5 ] ] [ state5: [ op1; op2 ] ] [ state6: [ op1; op2; op3; op4 ] ] [ state7: [ op1; op2; op3 ] ] [ state8: [ op1; op2; op3; op4 ] ] [ state9: [ op1; op2 ] ]

Will all of state1 (or state9) operations be completed before any of state2 (state8)?

If so, just enqueue() a bunch of Thread::Queue objects onto a Thread::Queue. Dequeue() them one at a time and dequeue() each operation one at a time and process it. But that isn't a state machine, it's just a pre-serialised series of operations.

If however, it is your intention that the first operation of any of states 1 thru 9 can be processed in any order -- which would make it a state machine -- then you aren't using a queue for the outer level; you are using a random access data structure. Ie. an array.

So, use an array of queues rather than abusing a queue of queues.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Comment on Re^3: How to create a two dimensional queue in Perl
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047940]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2015-11-28 15:11 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (743 votes), past polls