Re: GtkListStore and Threads problems
- From: Lorena Salinas <lsalinas invap com ar>
- To: Soeren Sandmann <sandmann daimi au dk>
- Cc: Owen Taylor <otaylor redhat com>, gtk-app-devel-list gnome org, Peter Bloomfield <peterbloomfield bellsouth net>
- Subject: Re: GtkListStore and Threads problems
- Date: Fri, 17 Jun 2005 11:56:09 -0300
Here is a test that I've run using gdb and had the following error:
Gtk-ERROR **: file gtksequence.c: line 760
(_gtk_sequence_node_find_by_pos): assertion failed: (node->parent !=
NULL)
aborting...
any help?
Regards,
Lorena
#include <gtk/gtk.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define STATUS_NORMAL 1
enum
{
TEST_COL_0 = 0,
TEST_COL_1,
TEST_COL_2,
TEST_COL_3,
TEST_COL_4,
TEST_COL_5,
TEST_COL_6,
TEST_COL_7,
TEST_NUM_COLS
} ;
pthread_mutex_t mutex;
GtkTreeModel * model;
gboolean bTerminated; /* Variable que controla el loop dentro del
thread */
gboolean upgrade_status (void)
{
static gboolean upgrading = FALSE;
GtkTreeIter iter;
gboolean valid;
int status;
g_assert (model);
if (upgrading) {
g_print("WARNING: Upgrading!!!\n");
return FALSE;
}
upgrading = TRUE;
pthread_mutex_lock(&mutex);
gdk_threads_enter(); /* get GTK thread lock */
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter);
gdk_threads_leave(); /* release GTK thread lock */
pthread_mutex_unlock(&mutex);
while (valid) {
gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
TEST_COL_5, &status,
-1);
pthread_mutex_lock(&mutex);
gdk_threads_enter(); /* get GTK thread lock */
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
TEST_COL_5, g_random_int_range(0,100),
-1);
gdk_threads_leave(); /* release GTK thread lock */
pthread_mutex_unlock(&mutex);
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter);
} /* while valid */
upgrading = FALSE;
return TRUE;
}
void *connectThread(void *data){
bTerminated = 0;
while (!bTerminated){
upgrade_status();
sleep(1);
} /* end while (!bTerminated) */
g_print ("pthread_exit(NULL)\n");
pthread_exit(NULL);
}
void create_thread (void)
{
pthread_t testThread;
gint res;
if ( gtk_tree_model_iter_n_children (model, NULL) > 0) {
res = pthread_create (&testThread , NULL, &connectThread, NULL);
if (res > 0) {
fprintf (stderr, "Error al crear thread");
}
}
} /* create_thread */
static GtkTreeModel *create_and_fill_model (void)
{
GtkTreeIter iter;
GtkListStore *store;
guint i;
store = gtk_list_store_new (TEST_NUM_COLS,
G_TYPE_INT,
G_TYPE_INT,
G_TYPE_INT,
G_TYPE_INT,
G_TYPE_INT,
G_TYPE_INT,
G_TYPE_INT,
G_TYPE_INT
);
for (i=1; i <= 100; i++){
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
TEST_COL_0, i,
TEST_COL_1, 1,
TEST_COL_2, 2,
TEST_COL_3, 3,
TEST_COL_4, 4,
TEST_COL_5, STATUS_NORMAL,
TEST_COL_6, 6,
TEST_COL_7, 7,
-1);
}
return GTK_TREE_MODEL (store);
} /* create_and_fill_model*/
GtkWidget * create_view_and_model (void)
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkWidget *view;
/* create the view */
view = gtk_tree_view_new ();
/* --- Column #X --- */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes("#",
renderer,
"text", TEST_COL_0,
NULL);
g_object_set (G_OBJECT (renderer), "xalign", 0.5, NULL);
gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id (column, TEST_COL_0);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
/* --- Column #X --- */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes("#",
renderer,
"text", TEST_COL_1,
NULL);
g_object_set (G_OBJECT (renderer), "xalign", 0.5, NULL);
gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id (column, TEST_COL_1);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
/* --- Column #X --- */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes("#",
renderer,
"text", TEST_COL_2,
NULL);
g_object_set (G_OBJECT (renderer), "xalign", 0.5, NULL);
gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id (column, TEST_COL_2);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
/* --- Column #X --- */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes("#",
renderer,
"text", TEST_COL_3,
NULL);
g_object_set (G_OBJECT (renderer), "xalign", 0.5, NULL);
gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id (column, TEST_COL_3);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
/* --- Column #X --- */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes("#",
renderer,
"text", TEST_COL_4,
NULL);
g_object_set (G_OBJECT (renderer), "xalign", 0.5, NULL);
gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id (column, TEST_COL_4);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
/* --- Column #X --- */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes("STATUS",
renderer,
"text", TEST_COL_5,
NULL);
g_object_set (G_OBJECT (renderer), "xalign", 0.5, NULL);
gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id (column, TEST_COL_5);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
/* --- Column #X --- */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes("#",
renderer,
"text", TEST_COL_6,
NULL);
g_object_set (G_OBJECT (renderer), "xalign", 0.5, NULL);
gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id (column, TEST_COL_6);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
/* --- Column #X --- */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes("#",
renderer,
"text", TEST_COL_7,
NULL);
g_object_set (G_OBJECT (renderer), "xalign", 0.5, NULL);
gtk_tree_view_column_set_alignment(column, 0.5);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_sort_column_id (column, TEST_COL_7);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
model = create_and_fill_model ();
gtk_tree_view_set_model (GTK_TREE_VIEW (view), model);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), TRUE);
// g_object_weak_ref (G_OBJECT (model), model_destroy_notify, NULL);
/* destroy model automatically with view */
g_object_unref (model);
return view;
} /* create_view_and_model */
void create_window (gchar * title, gint width, gint height )
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *scrolled_window;
GtkWidget *view;
pthread_mutex_init (&mutex, NULL); /* initializing the mutex object */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_type_hint(GTK_WINDOW (window),
GDK_WINDOW_TYPE_HINT_DIALOG);
gtk_window_set_title (GTK_WINDOW (window), title);
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK
(gtk_main_quit), NULL);
gtk_widget_show (window);
gtk_widget_set_size_request (GTK_WIDGET (window), width, height);
vbox = gtk_vbox_new (FALSE, 1);
gtk_widget_show (vbox);
gtk_container_add (GTK_CONTAINER (window), vbox);
/* create view */
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
(scrolled_window),GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
view = create_view_and_model();
gtk_container_add (GTK_CONTAINER (scrolled_window),view );
gtk_box_pack_start (GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
gtk_widget_show (view);
gtk_widget_show (scrolled_window);
} /* create_window */
int main (int argc, char **argv)
{
g_type_init();
/* init threads */
g_thread_init(NULL);
gdk_init(&argc, &argv);
gdk_threads_init();
gdk_threads_enter();
gtk_init (&argc, &argv);
create_window ("TEST", 100, 400);
create_thread ();
gtk_main ();
gdk_threads_leave(); /* release GTK thread lock */
return 0;
}
-------------------------------------------------------------------
Results:
(gdb) run --g-fatal-warning
Starting program: /home/lore/Projects/test/src/test --g-fatal-warning
[Thread debugging using libthread_db enabled]
[New Thread -1216235072 (LWP 28652)]
[New Thread -1217889360 (LWP 28655)]
Gtk-ERROR **: file gtksequence.c: line 760
(_gtk_sequence_node_find_by_pos): asser tion failed: (node->parent !=
NULL)
aborting...
Program received signal SIGABRT, Aborted.
[Switching to Thread -1216235072 (LWP 28652)]
0xffffe410 in __kernel_vsyscall ()
(gdb) backtrace
#0 0xffffe410 in __kernel_vsyscall ()
#1 0xb7a45175 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0xb7a467d8 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0xbfffefb0 in ?? ()
#4 0x00000000 in ?? ()
#5 0x00000020 in ?? ()
#6 0x00000000 in ?? ()
#7 0x00000000 in ?? ()
#8 0x00000000 in ?? ()
#9 0x00000000 in ?? ()
#10 0x00000000 in ?? ()
#11 0x00000000 in ?? ()
#12 0x00000000 in ?? ()
#13 0x00000000 in ?? ()
#14 0x00000000 in ?? ()
#15 0x00000000 in ?? ()
#16 0x00000000 in ?? ()
#17 0x00000000 in ?? ()
#18 0x00000000 in ?? ()
#19 0x00000000 in ?? ()
#20 0x00000000 in ?? ()
#21 0x00000000 in ?? ()
#22 0x00000000 in ?? ()
---Type <return> to continue, or q <return> to quit---
#23 0x00000000 in ?? ()
#24 0x00000000 in ?? ()
#25 0x00000000 in ?? ()
#26 0x00000000 in ?? ()
#27 0x00000000 in ?? ()
#28 0x00000000 in ?? ()
#29 0x00000000 in ?? ()
#30 0x00000000 in ?? ()
#31 0x00000000 in ?? ()
#32 0x00000000 in ?? ()
#33 0x00000000 in ?? ()
#34 0x00000000 in ?? ()
#35 0x00000000 in ?? ()
#36 0x00000000 in ?? ()
#37 0x0810a810 in ?? ()
#38 0x0806188c in ?? ()
#39 0xbffff048 in ?? ()
#40 0xb7b77c2d in g_free () from /usr/lib/libglib-2.0.so.0
Previous frame inner to this frame (corrupt stack?)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]