More thread problems
- From: Ola Andersson <rand ling umu se>
- To: gtk-list redhat com
- Subject: More thread problems
- Date: Wed, 20 Oct 1999 12:38:16 +0200
Why can't I access the gtk_label from a thread
in the program below? I'm using v1.2.6 of glib
and gtk+ (with the patch to gdataset.c I got from
this list).
I linked this program with:
-lpthread -lgthread -lgtk -lgdk -lX11 -lglib
---
#include <gtk/gtk.h>
#include <pthread.h>
GtkWidget *label;
pthread_t tid;
void *thread(void *arg)
{
gtk_label_set_text(GTK_LABEL(label),"Hello World");
return NULL;
}
void change_label(GtkWidget *widget,gpointer data)
{
pthread_create(&tid,NULL,thread,NULL);
}
int main(int argc,char **argv)
{
GtkWidget *window,*button,*box;
g_thread_init(NULL);
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(window),10);
label = gtk_label_new("label");
box = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(box),label,FALSE,FALSE,0);
gtk_widget_show(label);
button = gtk_button_new_with_label("Change label");
gtk_box_pack_start(GTK_BOX(box),button,FALSE,FALSE,0);
gtk_widget_show(button);
gtk_signal_connect(GTK_OBJECT(button),"clicked",GTK_SIGNAL_FUNC(change_label),NULL);
gtk_container_add(GTK_CONTAINER(window),box);
gtk_widget_show(box);
gtk_widget_show(window);
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
return 0;
}
--
Ola Andersson mailto:rand@ling.umu.se
Research Engineer http://www.ling.umu.se/~rand
Department of Phonetics Phone: +46 90 786 56 81
Umea University Fax: +46 90 786 63 77
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]