Re: quetion about gtk_input_add()
- From: ZHOU DX <zhou_dx yahoo com>
- To: Tristan Van Berkom <vantr touchtunes com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: quetion about gtk_input_add()
- Date: Mon, 3 Nov 2003 15:50:43 -0800 (PST)
Hi,
Thanks for that. But, I still have a few questions.
Logic in the controller thread seems not quite right
to me. I may have several childs, but the g_cond_wait
will return when the first exits. So the harvest may
only reap this first one. Am I wrong?
Also, I donot quite understand the g_thread_join part.
The child has already gone after leave the message to
the controller. So at that point, the controller may
join nothing. Am I right?
The reason why I ask this question is that I try to
avoid updating/redrawing the GUI in a thread context.
I dream that it would be nice if I can register a
callback function to the main loop, which is called
upon a "thread-exit" condition. (Like the idea of
gtk_input_add.) What I can do now is to call
"g_mutex_try_lock" in an idle function (gtk_idle_add)
to check a mutex that will be unlocked by a controller
when all worker threads exit. It looks not quite nice
though.
Thanks.
Dan
--- Tristan Van Berkom <vantr touchtunes com> wrote:
You could dedicate a thread to that.
i.e. (please dont expect precice code or argument
order... this is
obviously off the top of my head):
GList *dead_threads = NULL;
GMutex *killer = g_mutex_new();
GCond *kill_cond = g_condition_new();
/*
...
*/
g_thread_create( ... );
/*
...
*/
(in a child thread)
g_mutex_lock(killer);
dead_threads = g_list_append(dead_threads,
g_strdup("database_thread"));
g_condition_signal(... kill_condition ...);
g_mutex_unlocl(killer);
exit(0);
/*
...
*/
(in the "controller" thread)
g_mutex_lock(killer);
g_cond_wait( ... killer... kill_condition...);
g_mutex_unlock(killer);
list = g_list_first(dead_threads);
while (list && list->data) {
/* */
g_print("*** reaping thread %s ***\n",
list->data);
g_thread_join(/* use somthing associated with
string list->data */);
list = list->next;
}
/* free list ofcourse */
=====
----------------------------------------------------------
Have fun!
__________________________________________________________
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]