I just found this newsgroup - so I hope no one is annoyed that I'm
posting
something very similar to what i posted on c.l.p.m
I'm seeing unusual problems when i try to start a new thread from a
previously created thread.
I've written a INET socket program to respond to incoming messages with
new
messages sent out on a different socket.
I start a new thread for every incoming request .
When I don't need to spawn new threads the program works reliably.
However, some incoming requests have to create multiple responses so I'm
creating new threads...
I get seg faults when that happens with some of my tests
./agent.pl
Segmentation fault
./agent.pl
Segmentation fault
I also see leaked scalars when when it my test doesn't induce a seg
fault
here's the code that creates the inner threads:
Is there something wrong with this?
(I was surprised to find that I could not return multiple values from a
join
- thus the array_ref and splice)
foreach $subtask (@$ra_tasks) {
log_msg("Trying to schedule $subtask asynchronously\n",10);
#thread so these can occur simultaneously
$thr = threads->new(\&schedule_task,
$subtask,
$earliest_start,
$bid_by,
$req_id);
log_msg("adding thread $thr to list of workers\n", 12);
push @workers, $thr;
}
#now gather the results from the workers
foreach $thr (@workers) {
eval {
$ra_ret = $thr->join();
};
if ($@) {
die("subcontracing failed: [EMAIL PROTECTED]");
} else {
($start_time,$end_time, $ra_bids) = splice(@$ra_ret,0,3);
push @subtasks, {'first_start' => $start_time,
'last_end' => $end_time,
'bids' => $ra_bids};
}
}
--
Bradley W. Langhorst <[EMAIL PROTECTED]>