NAME
Pots::MessageQueue - Perl ObjectThreads thread safe message queue
SYNOPSIS
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');
$q->postmsg($msg);
$msg->type('quit');
$q->postmsg($msg);
DESCRIPTION
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.
METHODS
- 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.
AUTHOR and COPYRIGHT
Remy Chibois <rchibois at free.fr>
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.