develooper Front page | perl.ithreads | Postings from June 2008

thread hash bug?

Thread Next
From:
Wong, Danny H.
Date:
June 4, 2008 02:08
Subject:
thread hash bug?
Message ID:
D331130DD3DA194B96EF57DA3415F50A024C42CE@SAUSCUPEXCH01.corp.sa.net
Hi GURUS,

I'm trying to created a hash of array inside a thread, but the hash
loses all its keys/values when leaving the function. Is there a bug in
using a hash inside a thread? Any ideas?

foreach my $i ( 1..3){

push (@BUILD_THREADS, threads->create(\&COPY, $i));

}

foreach my $THREAD (@BUILD_THREADS)

{

my @DATA = $THREAD->join();

}

sub COPY

{

my ($i) = @_;

copy ( ${SOURCE}, "${DESTINATION}_${i}");

push @{$STORE_BUILD_RESULTS{"flintstones"}}, "${DESTINATION}_${i}";

while ( my ($KEY, $VALUE) = each (%STORE_BUILD_RESULTS))

{

print "KEY, VALUE is $KEY, @$VALUE\n";   #I get correct print out.

# $COMPLETED_BUILDS = STORE_BUILD_RESULTS

}

}

while ( my ($KEY, $VALUE) = each (%STORE_BUILD_RESULTS)) #The hash is
empty. Nothing gets printed out.

{

print "KEY, VALUE is $KEY, $VALUE\n";

# $COMPLETED_BUILDS = STORE_BUILD_RESULTS

}





     - - - - -                              Cisco                            - - - - -
This e-mail and any attachments may contain information which is confidential,
proprietary, privileged or otherwise protected by law. The information is solely
intended for the named addressee (or a person responsible for delivering it to
the addressee). If you are not the intended recipient of this message, you are
not authorized to read, print, retain, copy or disseminate this message or any
part of it. If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete it from your computer.
Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About