Welcome to the Monastery | |
PerlMonks |
What is the correct way to use Thread::Queue::Any ?by fx (Pilgrim) |
on Jan 07, 2004 at 16:09 UTC ( [id://319494]=perlquestion: print w/replies, xml ) | Need Help?? |
fx has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to use Thread::Queue::Any 0.07 by liz but need some help.
The following code works fine:
and prints We have returned 1234 as expected. The power of a queue, however, comes into its own when used with threads as it allows data to be passed around. It is here that I am having problems. The Thread::Queue::Any documentation describes the usage of each object method but doesn't give an example using threads. The following code was my first attempt to get Thread::Queue::Any working with threads:
but running it produces:
and then it just sits there doing nothing. The Perl 5.8.0 thread tutorial uses the idiom of enqueuing an undef to a queue so that the while loop handling dequeuing exits when the undef is dequeued. This does not seem to work with Thread::Queue::Any. Should it? In an example given in the above tutorial, the queue is passed to the thread as a parameter for the sub. I thought I might need something like that with Thread::Queue::Any so I tried the next piece of code:
but this too produced:
and then just sat there too. And so we reach my question - how should I really be using Thread::Queue::Any across threads? == fx, Infinity Is Colourless
Back to
Seekers of Perl Wisdom
|
|