0

I am using a file i/o based perl script. This script will be used in parallel by many threads. There is a chance of two threads use it at the same time stamp. I am using file i/o in the script i.e

open(FILE,"<",$file_array);
my @file_array = <FILE>;
close(FILE);

1) Is there a chance of resource sharing conflict on @file_array data structure between two parallel threads using the script at the same time stamp.

2) If so how to avoid it?

3) How does the memory allocation is handled during such cases?

Thanks, Abhishek

  • 2
    Without more code, you are safe. You have copied the content of the file without modifying it, therefore there is no issue. Reading a file should never cause a conflict... – abiessu Jan 14 '14 at 18:20
  • Check out these two questions to learn why lexical file handles, such as `my $fh` are better than using typeglobs, such as `FILE` when opening files: http://stackoverflow.com/questions/3276674/which-one-is-good-practice-a-lexical-filehandle-or-a-typeglob http://stackoverflow.com/questions/1479741/why-is-three-argument-open-calls-with-autovivified-filehandles-a-perl-best-pract – hmatt1 Jan 14 '14 at 19:42

1 Answers1

2

@file_array gets a unique memory address per process. Nothing to worry about.

Josh Goldberg
  • 121
  • 1
  • 2