in reply to Re: Perl and Threading
in thread Perl and Threading

Using Thread::Queue.

Logic:
- Collect list of things to process (into a Thread::Queue)
- Execute threads using Thread::Queue for loop
- Each thread has what it needs to process a Queue item

Using this style structure:
@threads=map {
  threads->create(sub {
  (all things required for each thread to process a Thread::Queue item via a while(defined()) { } structure)
  });
  } 1 .. <numthreads>;
$_->join for @threads

Not using the threads:shared.  (Looked at it a couple times, but not sure that I've encountered a use case for it -or- simply don't have sufficiently complex code to justify?)

Thanks!

Replies are listed 'Best First'.
Re^3: Perl and Threading
by choroba (Cardinal) on Nov 03, 2023 at 09:53 UTC
    Are you using any modules in your script? Note that many modules aren't thread safe or need special handling to stay like that.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      DBI is in use. Each thread has it's own local prepared statements for insert/update for the data its processing. eg: have tried to handle everything as each thread having it's own local information/variables/etc. and not shared across threads, per se.