Question about Threads
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,
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
Show quoted text
-----Original Message-----
From: AgentM [mailto:agentm@cmu.edu]
Sent: Saturday, November 08, 2003 4:01 PM
To: Leon Oosterwijk
Subject: Re: [HACKERS] Question about ThreadsAre 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 inpostgresql's
query
optimiser. We used pthreads and are able to spawn threadsto deal with
the
query optimization, however on exit of the thread thepostmaster 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@webopticon.com
¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
Import Notes
Reply to msg id not found: FF310004-1236-11D8-8E41-000A95672382@cmu.edu | Resolved by subject fallback
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?
Yes, the backend code is not thread-safe.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073