in reply to creating unknown number of threads and then join results
maybe locking the variable before I update it? I was thinking that each thread is updating a different hash key of the variable, so it should be safe to update this way? Or does it need to be locked before each join statement?
All your updates to %Found are done within the same thread, so there is no need to lock anything. Besides which %Found isn't a shared variable, so you couldn't lock it if you tried.
Any suggestions on how to do this better?
Apart from this:
foreach my $dir ( sort keys %Found ) { foreach my $item ( sort @{ $Found{$dir} } ) { push(@Final, $item); } }
Could be more efficiently written as:
foreach my $dir ( sort keys %Found ) { push(@Final, sort @{ $Found{$dir} }); }
Not really. It is hard to see any scope for you not getting all the results produced by the external commands.
Perhaps you could print out the size of @results before returning and then sum those and compare it with the size of @Final?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: creating unknown number of threads and then join results
by rudds_perl_habit (Novice) on Jul 30, 2013 at 16:36 UTC | |
by BrowserUk (Patriarch) on Jul 30, 2013 at 18:32 UTC | |
by rudds_perl_habit (Novice) on Jul 30, 2013 at 18:43 UTC | |
by BrowserUk (Patriarch) on Jul 30, 2013 at 18:54 UTC | |
by Anonymous Monk on Jul 31, 2013 at 00:22 UTC |