|
You asked: As a different request, I noticed that it would be nice to register (at thread create time) a callback function that is invoked to handle the result (in parent context) when join is called.
This can easily be done by creating a hash to register callbacks based on thread IDs:
my %callbacks;
my $thr = threads->create(...);
$callback{$thr->tid()} = \&callback;
Then wherever you monitor the thread termination queue, you get the ID of the completed thread and invoke the callback:
my $id = $q->dequeue();
$callback{$id}->($id);
The callback then joins with the thread and completes the work:
sub callback
{
my $id = $_[0];
my $thr = threads->object($id);
my $result = $thr->join();
...
}
|