Re: quetion about gtk_input_add()
- From: Tristan Van Berkom <vantr touchtunes com>
- To: ZHOU DX <zhou_dx yahoo com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: quetion about gtk_input_add()
- Date: Mon, 03 Nov 2003 16:16:00 -0500
ZHOU DX wrote:
Hi there,
Just a question about gtk_input_add(). I know that we
can use gtk_input_add() to monitor a socket in the gtk
main loop, and get notified if something happens to
it.
I am just wondering if there is any similar way to
check if a gthread is finished in the gtk event loop.
(Say I have four gthreads doing some time consuming
work. After all of them finish, I need display
something on the main window.)
Any idea? Thanks.
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 */
This is one of I'm sure many ways of writing "event based" code
for thread exits. (probably you can even catch the thread's exit status
with g_thread_join).
Regards,
-Tristan
--
"Life would be so much easier if we could just look at the source code."
-- Francios Baumier
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]