hi,
  I just want to find out how and when to use locks in
threads...
i have following program..
in following %bounds is global variable....
each thread will update %bounds....
and later i am using %bounds...

do i have lock the %bounds before each thread update ?


my %bounds = ();


for(@tmp_files){
            push(@threads, new threads(\&sort_it,$_));
}

sub sort_it{

#        my $ref = shift;
#        my $tmp = shift;

        my $chunk = shift;
        my $first = 1;
        #my $tid = $thread->tid();
        print "thread Sorting chunk : $chunk\n";
        my @buf = ();
        open(TMP,"$chunk") || die $!;
        push (@buf, $_) while(<TMP>);
        close(TMP);
        open(TMP,">$chunk") || die $!;
        for(sort {my $fields1 = substr($a,10,5);
                          my $fields2 = substr($b,10,5);
                          $fields1 <=> $fields2 } @buf){
                if($first){
                        $bounds{$chunk} = substr($_,10,5);
                        $first = 0;
                }
                print TMP $_;
        }
        close(TMP);
#               my @keys = keys %bounds;
#                print "keys : @keys\n";

}




__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to