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
In reply to Re: Re: Re: Re: Threading: Removing an element from a shared array
by P0w3rK!d
in thread Threading: Removing an element from a shared array
by P0w3rK!d
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |