gulden has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Adding Hash's to a Thread::Queue, it is possible? Serialize a Hash and put it in the Queue is an option? How?

#!/opt/coolstack/bin/perl use strict; use threads ('yield', 'stack_size' => 64*4096, 'exit' => 'threads_only', 'stringify'); use Thread::Queue; my $nloaders = 64; #--------------------------------------------------------------- my @thrs_loaders; my $queue = Thread::Queue->new(); for(1..$nloaders){ print "START LOAD $_ \n"; my ($thr) = threads->create(\&load, $_); push @thrs_loaders ,$thr; } $_->join for @thrs_loaders; exit; #--------------------------------------------------------------------- sub load{ my $id = shift; my $tmp; for(1..1e3){ my %rec = ('key_1' => 'val_1', 'key_2' => 'val_2'); $queue->enqueue(\%rec); # This give me an error: Invalid value fo +r shared scalar } print "STOP $id\n"; }

Replies are listed 'Best First'.
Re: How to put Hash's on Thread::Queue
by Anonymous Monk on May 13, 2009 at 10:37 UTC
      Confirmed, it works with
      C:\>pmvers threads threads::shared Thread::Queue threads: 1.72 threads::shared: 1.28 Thread::Queue: 2.11
      ActivePerl-5.8.9.825-MSWin32-x86-288577
        It doesn't work for me.
        -bash-3.00$ perl -MThread::Queue -e 'print $Thread::Queue::VERSION . " +\n"' 2.00 -bash-3.00$ perl -Mthreads::shared -e 'print $threads::shared::VERSION + . "\n"' 1.27 -bash-3.00$ perl -Mthreads -e 'print $threads::VERSION . "\n"' 1.71

        The problem was with the old version of Thread::Queue.

        Tks