Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Perlthrtut threadqueue example : possibly incorrect ? (http://www.velocityreviews.com/forums/t900819-perlthrtut-threadqueue-example-possibly-incorrect.html)

klestes@gmail.com 11-28-2006 04:31 PM

Perlthrtut threadqueue example : possibly incorrect ?
 
Messing with the example relating to the Thread::Queue, which is :

use threads;
use threads::shared;
use Thread::Queue;

my $DataQueue = new Thread::Queue;
$thr = async {
while ($DataElement = $DataQueue->dequeue) {
print "Popped $DataElement off the queue\n";
}
};

$DataQueue->enqueue(12);
$DataQueue->enqueue("A", "B", "C");
$DataQueue->enqueue(\$thr);
sleep 10;
$DataQueue->enqueue(undef);
$thr->join;

And I get an "invalid value for shared scalar". After further messing
around, discovered it works OK if I remove the following line:

$DataQueue->enqueue(\$thr);


So my question is: Wha ?


(Win32/ActiveState 5.8.7 in da house)


xhoster@gmail.com 11-28-2006 04:47 PM

Re: Perlthrtut threadqueue example : possibly incorrect ?
 
klestes@gmail.com wrote:
> Messing with the example relating to the Thread::Queue, which is :
>
> use threads;
> use threads::shared;
> use Thread::Queue;
>
> my $DataQueue = new Thread::Queue;
> $thr = async {
> while ($DataElement = $DataQueue->dequeue) {


They should probably check for definedness, not just for truth,
of the $DataElement.

> print "Popped $DataElement off the queue\n";
> }
> };
>
> $DataQueue->enqueue(12);
> $DataQueue->enqueue("A", "B", "C");
> $DataQueue->enqueue(\$thr);
> sleep 10;
> $DataQueue->enqueue(undef);
> $thr->join;
>
> And I get an "invalid value for shared scalar". After further messing
> around, discovered it works OK if I remove the following line:
>
> $DataQueue->enqueue(\$thr);
>
> So my question is: Wha ?


That is a limitation of Thread::Queue. I don't why they decided to
give an example of this limitation without stating that that is what they
were doing. Thread::Queue::Any should circumvent this problem.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB


All times are GMT. The time now is 06:06 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.