Gtk+ problem with multithreading
- From: patkhor <indyz-fluke hotmail com>
- To: gtk-app-devel-list gnome org
- Subject: Gtk+ problem with multithreading
- Date: Sun, 3 May 2009 00:36:22 -0700 (PDT)
Hi,
This is the first time I write GUI application using Gtk+ and I have some
problems
with multithreading.
What I want to achieve is that when the user clicks on OK button, the
program will call
callback_func which creates some number of threads (in this case, I use 5).
And each threads then start executing thread_func.
The problem I have is, when I click on OK button, the main window freezes
(display "Not responding"
message on Windows machine) until all the threads finish its execution.
The following is part of the code:
struct thread_data_t {
int member1;
int member2;
};
struct thread_data_t thread_data[5];
void *thread_func(void *threadarg) {
struct thread_data_t *thread_data;
thread_data = (struct thread_data_t *) threadarg;
.........................
.........................
return NULL;
}
void callback_func(GtkWidget *button, gpointer data) {
GThread *threads[5];
int i;
...................
...................
for (i = 0; i < 5; i++)
threads[i] = g_thread_create((GThreadFunc)thread_func, (void
*)(&thread_data[i]), TRUE, &err[i]);
for (i = 0; i < 5; i++)
g_thread_join(threads[i]);
...................
...................
}
int main(int argc, char *argv[]) {
g_thread_init(NULL);
gdk_threads_init();
gtk_init(&argc, &argv);
..................
..................
g_signal_connect(GTK_OBJECT(ok_button), "clicked",
GTK_SIGNAL_FUNC(callback_func), (gpointer *)&arg);
..................
..................
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
return 0;
}
Any help would be highly appreciated,
Pat
PS. Sorry for my bad English. It's my second language.
--
View this message in context:
http://www.nabble.com/Gtk%2B-problem-with-multithreading-tp23353368p23353368.html
Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]