It is an actual data structure reference. I have this in some of my code somewhere:
$pm->run_on_finish( sub { $buckets->{$_[0]} = $_[1] for @{$_[5]}; } );
So that means that $_[5] ($data_structure_reference) is shaped something like:
$data_structure_reference = [ ['a', 1], ['e', 1], ['l', 1], ['p', 2], ]
Keep in mind the following information from the POD for Parallel::ForkManager:
The ability for the parent to retrieve data structures is new as of version 0.7.6.
Each child process may optionally send 1 data structure back to the parent. By data structure, we mean a reference to a string, hash or array. The contents of the data structure are written out to temporary files on disc using the Storable modules' store() method. The reference is then retrieved from within the code you send to the run_on_finish callback.
The data structure can be any scalar perl data structure which makes sense: string, numeric value or a reference to an array, hash or object.
There are 2 steps involved in retrieving data structures:
1) A reference to the data structure the child wishes to send back to the parent is provided as the second argument to the finish() call. It is up to the child to decide whether or not to send anything back to the parent.
2) The data structure reference is retrieved using the callback provided in the run_on_finish() method.
Keep in mind that data structure retrieval is not the same as returning a data structure from a method call. That is not what actually occurs. The data structure referenced in a given child process is serialized and written out to a file by Storable. The file is subsequently read back into memory and a new data structure belonging to the parent process is created. Please consider the performance penalty it can imply, so try to keep the returned structure small.
In the case of my code example, the data structure is being layered into a hash that has been in scope since before the forked children were created.
Dave
In reply to Re: Parallel:ForkManager how to pass back a list
by davido
in thread Parallel:ForkManager how to pass back a list
by cormanaz
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |