Re: Widgets and GThreads.
- From: Brian Kerrick Nickel <kerrick cox net>
- To: gtk-list gnome org
- Subject: Re: Widgets and GThreads.
- Date: Mon, 07 Jun 2004 12:03:03 -0700
There is a function in glib called g_idle_add which makes it so the
function will be called in the main loop, avoiding locking problems.
What I typically do is wrap functions like I've shown below so you
basically call thread_button_set_label instead of gtk_button_set_label
and everything works out. The code below basically takes the data,
sticks it into the pointer that g_idle_add needs, and sends it through
to be processed. I haven't tested the code but I think it's all correct.
- Brian
typedef struct
{
GtkButton *button;
gchar *label;
} ButtonData;
void thread_button_set_label_BD (ButtonData *data)
{
gtk_button_set_label (data->button, data->label);
g_free (data->label);
g_free (data);
}
void thread_button_set_label (GtkButton *button, gchar *label)
{
ButtonData *data = g_alloc (sizeof (ButtonData));
data->button = button;
data->label = g_strdup( label );
g_idle_add (thread_button_set_label_BD, data);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]