Pots::MessageQueue - Perl ObjectThreads thread safe message queue


    use threads;

    use Pots::MessageQueue;
    use Pots::Message;

    my $q = Pots::MessageQueue->new();

    sub thread_proc {
        my $rmsg;
        my $quit = 0;

        while (!$quit) {
            $rmsg = $q->getmsg();

            for ($rmsg->type()) {
                if (/quit/) {
                    $quit = 1;
                } else {
                    print "thread received a message of type $_\n";

    my $th = threads->new("thread_proc");

    my $msg = Pots::Message->new('type');



Pots::MessageQueue objects allows threads to communicate using messages. It is built upon a standard Thread::Queue object, and uses Storable to serialize and deserialize messages between threads.


new ()

Construct a new, shared, message queue object.

postmsg ($msg)

Posts a message in the queue, so that a thread can retrieve it using "getmsg()".

getmsg ()

Retrieves a message from the queue. If no message is available, this method will wait until a message becomes available.

nbmsg ()

Returns the number of messages waiting in the queue.


Remy Chibois <rchibois at>

Copyright (c) 2004 Remy Chibois. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.