|XP is just a number|
Multi-threads newbie questionsby daverave (Scribe)
|on Sep 20, 2010 at 08:07 UTC||Need Help??|
daverave has asked for the
wisdom of the Perl Monks concerning the following question:
I am using Perl 5.10.1 under Ubuntu 10.04.
This is the outline of my task. I would like to write a subroutine ('my_sub') that gets a reference to a hash of hashes (hoh). A second subroutine ('helper') will work on a single 'inner' hash.
The work on each of the internal hashes is independent of the others, so I would like to use multi-threading to speed things up.
I'm using 'Thread::Pool::Simple' which almost lacks any documentation as far as I can tell. I also looked at 'Thread::Pool', but it seems some of its dependencies are not supported by my Perl version.
The key point that I have difficulties with is the fact that I would like 'helper' to update the (inner) hash it gets. For example, I would like 'helper' to add keys to the hash.
First, I tried writing 'helper' as a subroutine that gets a (inner) hashref, so it looks something like this:
'my_sub' gets an unshared reference (to $hohref) so I tried creating a shared copy in the body of `my_sub`: my $shared_hohref = shared_clone $hohref; the use it and finally return it but the internal hashes were not updated. When I use the exact same code, but simply replace all the thread pool block with a simple loop (i.e. quit using multi-threading)
then everything works fine.
Your help would be greatly appreciated.
See this runnable example:
'helper starts' but that's it... what ever happens to it?