Re: Question about Threads

From: "Leon Oosterwijk" <leon(at)isdn(dot)net>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Question about Threads
Date: 2003-11-08 23:41:52
Message-ID: 200311082341.hA8Nfrv00717@rex.isdn.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

AgentM,

The treads are joined back together by the master. I did try to debug, but
have to say I hard a hard time with it. I have tried to debug, but didn't
get very far. Debugging Threads is not my forte. :(

Here is the code from :
/src/backend/optimizer/geqo/geqo_main.c

for (i=0;i<thread_count;i++)
{
geqo_params[i].root = copyObject(root);
geqo_params[i].number_of_rels = number_of_rels;
geqo_params[i].initial_rels = copyObject(initial_rels);

geqo_params[i].root->base_rel_list =
listCopy(root->base_rel_list);
geqo_params[i].root->other_rel_list =
listCopy(root->other_rel_list);
geqo_params[i].root->join_rel_list =
listCopy(root->join_rel_list);
geqo_params[i].root->equi_key_list =
listCopy(root->equi_key_list);
geqo_params[i].root->query_pathkeys =
listCopy(root->query_pathkeys);

geqo_params[i].myid = i;

pthread_create(&thread_list[i],
NULL,
(void *(*)(void *)) geqo_single , (void *)
&geqo_params[i]);
}

// join all thread and get results
for (i=0;i<thread_count;i++)
{
elog(DEBUG1, "geqo: trying to join back thread %d", i);
pthread_join(thread_list[i],(void *) results[i]);
// sort results
if (best_so_far == -1)
{
elog(DEBUG1, "geqo: thread %d is first thread we
see", i);
best_so_far = i;
}
else
{
if
(results[best_so_far]->cheapest_total_path->total_cost >
results[i]->cheapest_total_path->total_cost)
{
elog(DEBUG1, "geqo: thread %d is better than
thread %d ", i, best_so_far);
best_so_far = i;

}
}

Leon

> -----Original Message-----
> From: AgentM [mailto:agentm(at)cmu(dot)edu]
> Sent: Saturday, November 08, 2003 4:01 PM
> To: Leon Oosterwijk
> Subject: Re: [HACKERS] Question about Threads
>
> Are you using joined or detached pthreads? Have you tried debugging?
>
> On Saturday, Nov 8, 2003, at 22:47 Europe/Berlin, Leon
> Oosterwijk wrote:
>
> > All,
> >
> > I'm working on a school project that involves genetic
> algorithms. We
> > thought
> > it would be neat to parralelize the genetic algorithm in
> postgresql's
> > query
> > optimiser. We used pthreads and are able to spawn threads
> to deal with
> > the
> > query optimization, however on exit of the thread the
> postmaster blows
> > up.
> > Before we get into details is there any obvious reason postgres
> > doesn't like
> > to deal with threads?
> >
> > Thank you.
> >
> > Leon
> ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
> AgentM
> agentm(at)webopticon(dot)com
> ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
>

Browse pgsql-hackers by date

  From Date Subject
Next Message Marko Karppinen 2003-11-08 23:44:49 Re: Making PostgreSQL 7.4 (CVS) work properly on OS X 10.3 (7B85)
Previous Message Bruce Momjian 2003-11-08 23:36:38 Re: Call for port reports