threading problems...please help with workaround
- From: Brad House <brad mainstreetsoftworks com>
- To: gtk-list gnome org
- Subject: threading problems...please help with workaround
- Date: Wed, 15 Aug 2001 17:32:44 -0400
I posted yesterday, but am no closer to a solution
with the suggestions I recieved...
here is my improperly functioning code snipet....
(attached file gtk-thread.c)
it's simply trying to hide and show a window out
of a thread...it doesn't work until I move the mouse
over the area for the window. Though if I hide
and show the label within the window, it functions
properly with out having to do anything else.
Is this a bug? I've got all the threading stuff down
as far as I can figure.
Please help.
Compile with
gcc `gtk-config --cflags gthread` -o gtk-thread gtk-thread.c `gtk-config
--libs gthread` -lpthread
-----------------------------
Brad House
Sr. Developer
Main Street Softworks, Inc.
brad mainstreetsoftworks com
(352) 378-8228
-----------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <gtk/gtk.h>
#include <pthread.h>
GtkWidget *window;
GtkWidget *label;
void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
void *run_thread(void *args)
{
int visible=1;
while (1) {
sleep(1);
//GDK_THREADS_ENTER();
gdk_threads_enter();
if (visible) {
visible=0;
gtk_widget_hide(window);
} else {
visible=1;
gtk_widget_show(window);
}
// g_main_iteration(FALSE);
gdk_threads_leave();
//GDK_THREADS_LEAVE();
}
}
int main(int argc, char *argv[])
{
pthread_t thread;
g_thread_init(NULL);
/* init gtk */
gtk_init(&argc, &argv);
/* create a window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC(destroy), NULL);
gtk_container_set_border_width(GTK_CONTAINER (window), 10);
/* create a label */
label = gtk_label_new("This window should hide and show itself once a second...from a thread");
gtk_container_add(GTK_CONTAINER(window), label);
/* show everything */
gtk_widget_show(label);
gtk_widget_show (window);
if (g_thread_supported())
printf("g_thread_supported is true\r\n"); // Yep....compiled with thread support and initialized
if (gdk_threads_mutex)
printf("mutex initialized\r\n"); // yep the mutex is definately initialized..
/* create the thread */
pthread_create(&thread, NULL,(void *)run_thread, NULL);
/* enter the GTK main loop */
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
return(0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]