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'); $q->postmsg($msg); $msg->type('quit'); $q->postmsg($msg);
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.
Pots::MessageQueue
Thread::Queue
Storable
Construct a new, shared, message queue object.
Posts a message in the queue, so that a thread can retrieve it using "getmsg()".
Retrieves a message from the queue. If no message is available, this method will wait until a message becomes available.
Returns the number of messages waiting in the queue.
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.
To install Pots::Thread, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pots::Thread
CPAN shell
perl -MCPAN -e shell install Pots::Thread
For more information on module installation, please visit the detailed CPAN module installation guide.