Adler has asked for the wisdom of the Perl Monks concerning the following question:
after running this code, i get#!/usr/bin/perl -w use warnings; use strict; use threads; use threads::shared; my @Array : shared = (); my $thr = threads->create( \&handle_array , \@Array ); while( 1 ) { do_something(\@Array); printf "Main: Number of files: ". scalar(@Array) . "\n"; sleep 5; } sub do_something { my ( $Array_ref ) = shift; push( @{$Array_ref} , {file => 'test1.zip', price => '10.00', d +esc => 'the 1st test'} ); sleep 10; } sub handle_array { my ( $Array_ref ) = shift; while (1) { printf STDOUT "Thread: Number of elements before: %d\n", scala +r(@{$Array_ref}); push( @{$Array_ref} , {file => 'test1.zip', price => '10.00' +, desc => 'the 1st test'} ); printf STDOUT "Thread: Number of elements after: %d\n", scalar +(@$Array_ref); sleep 10; } }
Invalid value for shared scalar at foo.pl line 22.
since i am newbie, do i need to use "\" to my array? it make sence, but if it is from the first place shared, then... Regards
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: share array of hashes between main program and thread
by BrowserUk (Patriarch) on Nov 05, 2009 at 20:55 UTC | |
by Adler (Novice) on Nov 11, 2009 at 07:39 UTC | |
by BrowserUk (Patriarch) on Nov 11, 2009 at 07:51 UTC | |
by Adler (Novice) on Nov 11, 2009 at 11:54 UTC | |
by BrowserUk (Patriarch) on Nov 11, 2009 at 12:01 UTC | |
|
Re: share array of hashes between main program and thread
by bichonfrise74 (Vicar) on Nov 05, 2009 at 20:55 UTC |