Dean Arnold wrote:
Christopher Fowler wrote:
On Tue, 2006-10-10 at 09:23 -0500, Michael J. Pomraning wrote:

I've done a quick rewrite of your example (note I have no idea what
the function of your script is, but the Packet class is a pretty simple container
class, so hopefully this captures what you're attempting).

Big OOOPS on my part. I forgot one little detail: you have to rebless
the object when its dequeue'd:


sub process_thread {
    while(1) {

#
#    wait for a packet (or for 'DIE')
#
        my $pktobj = $q->dequeue();
#
#    if not a ref, then it must be 'DIE'
#
        return 1
            unless ref $pktobj;

#
#       You have to rebless in the receiving thread
#
        bless $pktobj, 'Packet';
#
# Get the packet off the list and unpack the time
#
        my $pkt = $pktobj->get_packet();
        my $ti = $pktobj->get_timestamp();

FWIW (and blatant plug): if your Packet class becomes more complex, esp.
if it has object refs or file handles as members,
you might check out Thread::Queue::Duplex, which provides a
Thread::Queue::Queueable base class which your Packet class can subclass
to implement its own marshalling/unmarshalling (aka curse()/redeem())
methods to deal with recovering things.

Dean Arnold
Presicient Corp.

Reply via email to