Here is the basic code that I want convert to threading:
@tokens is an array of about 80K things. For each token, I build a custom regex for each particular token which is then run against all other tokens. What I'm looking for are the other tokens that "sort of match" each token. All of the rules for what counts as "close enough" are built into the build_regex() function. That whole subject is complicated and beyond my question here.my %result; foreach my $token (@tokens) { my $regex = build_regex($token); my @line_results = grep {$_ ne $token and /$regex/ }@tokens; $result{$token} = [@line_results]; }
Yes, this is a brute force N*N execution time. Right now, this takes about 90 minutes. I want this to run at least 3x faster. I have a 4 core machine and that sounds feasible.
I have been looking at Re: Perl Threads Boss/Worker Example as an example of worker threads. I can see that I build a queue of the @tokens + 4 undef values for a 4 thread limit. What I don't understand is how the combined results can be generated without the threads "stepping upon each other" How can threads write to a global structure accessible to them all?
In reply to Multi-thread combining the results together by Marshall
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |