On onsdag, apr 2, 2003, at 03:19 Europe/Stockholm, Bradley W. Langhorst wrote:
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
Not at all, :)
I'm seeing unusual problems when i try to start a new thread from a previously created thread.
This has been known to be a bit wonky on Win32, but not under unix (which I assume you are using because you like forks.pm)
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
A backtrace would be nice,,
gdb perl run ./agent.pl bt
I also see leaked scalars when when it my test doesn't induce a seg fault
Probably the same thing.
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)
Because of some unknown reason the thread runs with the context of when it is created, so to return an array you need to do
($thread) = threads->new(....
so the thread gets a list context
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}; } }
Do you know when you are getting the coredump, in new() or in join?
Also, what modules are you using?
Arthur
