Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perlthrtut threadqueue example : possibly incorrect ?

Reply
Thread Tools

Perlthrtut threadqueue example : possibly incorrect ?

 
 
klestes@gmail.com
Guest
Posts: n/a
 
      11-28-2006
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)

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      11-28-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about the example in perlthrtut jl_post@hotmail.com Perl Misc 5 04-03-2009 05:36 AM
'example.com' == 'example.com.' => false... is this intended? Sam Roberts Ruby 15 02-07-2005 04:36 PM
interfearance, possibly from cordless phones? is there a fix? =?Utf-8?B?R3JlZw==?= Wireless Networking 8 10-05-2004 01:42 PM
Net::SNMP dies on any OID error and doesn't return other possibly good values dan byers Perl 1 03-06-2004 09:50 AM
Problem with arrays or possibly HTML::Element Brett Perl 0 12-19-2003 06:13 AM



Advertisments