Re: multithreading on win32
- From: Christophe Combelles <ccomb free fr>
- To: Harring Figueiredo <harringf yahoo com>, gtk-app-devel-list gnome org
- Subject: Re: multithreading on win32
- Date: Mon, 03 May 2004 20:20:08 +0200
It has never been impossible to control the GUI from a thread -- as a matter
of fact, the GUI is controlled by a thread itself :). Now, if you are talking
about having multiple threads accessing the GUI data structures, you will have
to provide the synchronization yourself.
gdk_threads_enter() and gdk_threads_leave() are your friends.
There are several apps that do that: Gaim and Urlget are 2 that comes to
mind.
Hope this helps.
Harring Figueiredo
I would like to something like that (see below):
But it doesn't work. The window disappears immediatly when the thread finishes,
and if the thread is kept alive (uncomment "sleep"), the window is frozen.
I just need to create a thread, and that thread must notify the user of its
activity. (at least when it starts and stop, or with a progress bar)
-----------test.c--------------------
#include <gtk/gtk.h>
GtkWidget *window;
GtkWidget *label;
GThread *thread;
gint function() {
gdk_threads_enter();
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
label=gtk_label_new("my text");
gtk_container_add(GTK_CONTAINER(window), label);
gtk_widget_realize(window);
gtk_widget_show_all(window);
gdk_threads_leave();
//sleep(10000);
}
gint main(int argc, char *argv[]) {
g_thread_init (NULL);
gdk_threads_init();
gtk_init(&argc,&argv);
thread = g_thread_create((GThreadFunc)function, NULL, TRUE, NULL);
g_thread_join(thread);
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
}
--------------------------------------------
compiled on MinGW with:
gcc -g -DDEBUG -mms-bitfields -mwindows `pkg-config --cflags gtk+-2.0` -c test.c
-o test.od
gcc -static -mms-bitfields -mwindows -o test.exe test.od `pkg-config --libs g
tk+-2.0 --libs gthread-2.0` -L/lib
--------------------------------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]