# New Ticket Created by [EMAIL PROTECTED] # Please include the string: [perl #32074] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=32074 > Using Perl 5.8.4 and 5.8.5, I had problems with Scripts like these:
------------------ #!/usr/bin/perl
use Thread;
Why use Thread? Please do a "perldoc Thread" and see that it says:
For new code the use of the "Thread" module is discouraged and the direct use of the "threads" and "threads::shared" modules is encouraged instead.
So, please do a "use threads;"
use Thread::Queue;
$queue = Thread::Queue->new();
$producer = Thread->new(\&produce, $queue); $consumer = Thread->new(\&consume, $queue);
s/Thread/threads/ here as well.
$producer->join(); $consumer->join();
sub produce { my ($queue) = @_; foreach $i (1..10) { $queue->enqueue($i); print "Produced $i\n"; sleep(rand(3)); } }
sub consume { my ($queue) = @_; my $val; do { $val = $queue->dequeue(); print "Consumed $val\n"; } while($val != 10); } --------------------------------------
Seems to work fine then:
$ perl not_consuming.pl Produced 1 Consumed 1 Produced 2 Consumed 2 Produced 3 Consumed 3 Produced 4 Produced 5 Consumed 4 Consumed 5 Produced 6 Produced 7 Consumed 6 Consumed 7 Produced 8 Produced 9 Consumed 8 Consumed 9 Produced 10 Consumed 10 $
Namely, the dequeue method blocks forever when the queue is empty, even when new data gets available.
The perl interpreter was compiled with the new multithreading support, and Threads themselves worked perfectly.
The cond_wait, cond_signal and cond_broadcast functions (which are required for Thread::Queue to work properly) don't seem to work.
I tried several other scripts on several linux machines, and it all came down to cond_wait and cond_signal not working as expected.
Please notify me if you have resolved this issue.
with best regards,
Kai Londenberg
Stop using "Thread.pm" and use "threads.pm" instead. You should be fine.
Liz