Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: Re: Re: Threading: Removing an element from a shared array

by P0w3rK!d (Pilgrim)
on May 16, 2003 at 14:37 UTC ( [id://258659]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://258659]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found