in reply to Re: Re: Re: Threading: Removing an element from a shared array
in thread Threading: Removing an element from a shared array

Hi,
Thank you for your reply. This part of the system I am working on periodically reads a directory, builds an array, and threads calls to process each file in the array.

Given n number of elements in the array, I have limited the number of threads I am using so the process can send 1..$threads thread per file in given a subsets of the files. (I am trying to give each thread a unique index into the array so there are no deadlocks.) The code is something like this:

# PSEUDOCODE ... our $MAXTHREADS = 5; our @aryItems : shared; ... main(); sub main {...} sub process { my $threads = 0; my $files = (@aryItems); if ($files > $MAXTHREADS) { $threads = $MAXTHREADS; } initThreads($threads, ...); ... } sub initThreads { ... my $threads = 0; ... ($threads, ...) = @_; our @threads = (); for (0..$threads - 1) { push @threads, threads->new( \&Foo::run, id => $_, ... ); } } ... #### Foo class #### package Foo; use threads; use threads::shared; ... sub new{...}; sub run{<processing and locking code goes here>};

-P0w3rK!d

  • Comment on Re: Re: Re: Re: Threading: Removing an element from a shared array
  • Download Code