GUI Locks with gthreads
- From: Miraclesoa Miraclesoa <miraclesoa yahoo es>
- To: gtk-app-devel-list gnome org
- Subject: GUI Locks with gthreads
- Date: Tue, 9 Mar 2004 12:44:26 +0100 (CET)
Hi all
I have a problem with my GUI and gthreads.
I have two threads: one reads data from the database
and puts them into a buffer. Other reads the buffer
and updates some gtklabels.
My application (GUI) locks after a few minutes. I do
not know what I am doing wrong.
I put some of my code:
//Here I created the threads
g_thread_create(consultar_valores_ciclo,NULL,FALSE,NULL);
g_thread_create(actualizar_valores_ciclo,NULL,FALSE,NULL);
//Here is the consultar_valores_ciclo function
static void consultar_valores_ciclo()
{
GThread* self=NULL;
gchar *aux1=NULL;
gint mic;
while (1)
{
g_mutex_lock(gmx);
if (zfin==0)
{
if (gmx != NULL)
{
consultar_valores(); //reads data from db
g_timer_reset(zparo);
g_timer_start(zparo);
zini=g_timer_elapsed(zparo,NULL);
while(zini==0 && zfin==0)
{
zini=g_timer_elapsed(zparo,NULL);
}
g_timer_stop(zparo);
zini=0;
if(zfin==1)
{
self = g_thread_self();
g_mutex_unlock(gmx);
g_thread_exit(self);
}
}
}
if(zfin==1)
{
self = g_thread_self();
g_mutex_unlock(gmx);
g_thread_exit(self);
}
g_mutex_unlock(gmx);
}
}
//Here is the actualizar_valores_ciclo function
static void actualizar_valores_ciclo()
{
GThread* self=NULL;
gchar *aux1=NULL;
gint mic=0;
while (1)
{
g_mutex_lock(gmx);
if (zfin==0)
{
if (gmx != NULL)
{
actualizar_valores();
g_timer_reset(zparo);
g_timer_start(zparo);
zini=g_timer_elapsed(zparo,NULL);
while(zini==0 && zfin==0)
{
zini=g_timer_elapsed(zparo,NULL);
}
g_timer_stop(zparo);
zini=0;
if(zfin==1)
{
self = g_thread_self();
g_mutex_unlock(gmx);
g_thread_exit(self);
}
}
}
if(zfin==1)
{
self = g_thread_self();
g_mutex_unlock(gmx);
g_thread_exit(self);
}
g_mutex_unlock(gmx);
}
}
I also put the code :
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
I also put this code :
gdk_threads_enter();
label =
lookup_widget(GTK_WIDGET(toplevel),"label_name");
gtk_label_set_text(GTK_LABEL(label), "whatever");
gdk_threads_leave();
Thanks in advance and best regards
boricles
P.D. Sorry my poor english
___________________________________________________
Yahoo! Messenger - Nueva versión GRATIS
Super Webcam, voz, caritas animadas, y más...
http://messenger.yahoo.es
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]