gulden has asked for the wisdom of the Perl Monks concerning the following question:
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 | |
by Anonymous Monk on May 13, 2009 at 11:01 UTC | |
by gulden (Monk) on May 13, 2009 at 14:01 UTC |