Problem with Thread::Queue fixed. The sample program for Thread::Queue is
incorrect (or maybe I just missed the ":shared" when declaring variable @Q).
Well it is definitely incorrect in Larry's book: Programming Perl, 3rd
Edition.

Do they need a volunteer to update the documentation?

This works for me on windows.

Siegfried

#!c:/Perl/bin/Perl.exe

use strict;
use warnings;

# Begin commands to execute this file using Perl with bash
# ./test-threads.pl
# End commands to execute this file using Perl with bash

use threads;
use threads::shared;
use Thread::Queue;
use Thread 'async';

# Current time stuff
use POSIX qw(strftime);
use Time::localtime;
$| = 1;
print __LINE__." start, create queue\n";
my $Q : shared = Thread::Queue->new();

sub pump {
  my $id = shift; my $datam;  my $bDone = 0;
  while(!$bDone && defined($datam = $Q->dequeue)){
    print __LINE__.": $id Pulled ".(defined $datam?$datam:" NO DATUM")."
from queue\n";
    $bDone = $datam eq "done" if defined $datam;
  }
  print __LINE__. ": $id thread exit\n";
};
my @t = (Thread->new( \&pump, 1), Thread->new( \&pump, 2),
Thread->new(\&pump, 3));

$Q->enqueue($_) for 1..3;
$Q->enqueue("A", "B", "C");
$Q->enqueue($_) for 4..6;
$Q->enqueue("done") for 1..4;
$_->join() for @t;
print __LINE__." main existing\n";


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to