Perlthrtut threadqueue example : possibly incorrect ?

K

klestes

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)
 
X

xhoster

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top