On Thursday 08 October 2009 13:45:08 Matt Hammond wrote:
> Yes, its
> purpose when I coded it was to ensure queues are flushed.

It does not guarantee in order delivery though, when you chain 2 threaded 
components together

Specifically, given this sequence of messages being *logically* sent:

ProducerThread
    ( 1, "outbox")
    ( 2, "outbox")
    ( 3, "outbox")

    ( 4, "outbox")
    ( 5, "outbox")
    ( 6, "outbox")

    ( 7, "outbox")
    ( 8, "outbox")
    ( producerFinished, "signal")

Note that I've divided those into 3 chunks of messages.
These get appended to outqueues in that order.  Due to the way this loop...

          for box in self.outboxes:

... works this ensures that these will get sent to the actual outboxes as 
follows:
    ( 1, "outbox")
    ( 2, "outbox")
    ( 3, "outbox")

    ( 4, "outbox")
    ( 5, "outbox")
    ( 6, "outbox")

    ( 7, "outbox")
    ( 8, "outbox")
    ( producerFinished, "signal")

This arrives in the inboxes of the recipient:
    ( 1, "inbox")
    ( 2, "inbox")
    ( 3, "inbox")

    ( 4, "inbox")
    ( 5, "inbox")
    ( 6, "inbox")

    ( 7, "inbox")
    ( 8, "inbox")
    ( producerFinished, "control")

Now we hit the problem point. We hit this loop:
          for box in self.inboxes:

This causes this delivery order - control box, then inbox. This comes in fits 
and starts - due to timeslice interleaving:
   { no control messages }
    ( 1, "inbox")
    ( 2, "inbox")
    ( 3, "inbox")

   { no control messages }
    ( 4, "inbox")
    ( 5, "inbox")
    ( 6, "inbox")

    ( producerFinished, "control")
    ( 7, "inbox")
    ( 8, "inbox")

The consumer then exits early. This is because order is not guaranteed in this 
way by the implementation. It's a rather subtle bug, one only really visible 
if you are connecting two threads together.


Michael.
-- 
http://yeoldeclue.com/blog
http://twitter.com/kamaelian
http://www.kamaelia.org/Home

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"kamaelia" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/kamaelia?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to