GTK Thread init problem



hi
i am trying to use a threaded GTK program. While running the
program it gives segmentation fault and it seem to be an
thread init problem. is there any thing i am missing? Please
give u r comments.

the code is:
/***********************gtk19.c**************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <pthread.h>

pthread_t thrd1;

void destroy (GtkWidget *widget, gpointer data)
{
gtk_main_quit ();
}

void *argument_thread (void *args)
{
gdk_threads_enter ();
for (;;)
  {
    /* sleep a while */



        sleep(1);
        g_print("Inside thread");


  }
gdk_threads_leave ();
return NULL;
}

int main (int argc, char *argv[])
{
GtkWidget *window;

 /* init threads */

g_thread_init (NULL);
gdk_threads_init ();
/* init gtk */
gdk_threads_enter ();
/*[Line :70] */                gtk_init(&argc, &argv);

g_print("After init\n");

/* 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);
gtk_widget_show (window);

pthread_create (&thrd1, NULL, argument_thread, NULL);

gtk_main ();
gdk_threads_leave ();

return 0;
}
/**************************************************/

I compile it as
gcc -Wall -g gtk19.c -o base -lpthread `pkg-config --cflags gtk+-2.0`
`pkg-config --libs gtk+-2.0` `gtk-config --cflags --libs gthread`


After core dump bt gives
#0  0x00484aa2 in pthread_mutex_lock () from /lib/libpthread.so.0
#1  0x0025f63a in g_mem_chunk_new () from /usr/lib/libglib-2.0.so.0
#2  0x002408c6 in g_ptr_array_sized_new () from /usr/lib/libglib-2.0.so.0
#3  0x002408e3 in g_ptr_array_new () from /usr/lib/libglib-2.0.so.0
#4  0x00146f0d in gdk_x11_atom_to_xatom () from /usr/lib/libgdk-x11-2.0.so.0
#5  0x00146f7b in gdk_atom_intern () from /usr/lib/libgdk-x11-2.0.so.0
#6  0x001454d9 in gdk_keymap_translate_keyboard_state () from
/usr/lib/libgdk-x11-2.0.so.0
#7  0x0011267e in gdk_pre_parse_libgtk_only () from /usr/lib/libgdk-
x11-2.0.so.0
#8  0x00598330 in gtk_disable_setlocale () from /usr/lib/libgtk-x11-2.0.so.0
#9  0x00264c8c in g_option_context_parse () from /usr/lib/libglib-2.0.so.0
#10 0x00598789 in gtk_parse_args () from /usr/lib/libgtk-x11-2.0.so.0
#11 0x005987c3 in gtk_init_check () from /usr/lib/libgtk-x11-2.0.so.0
#12 0x00598801 in gtk_init () from /usr/lib/libgtk-x11-2.0.so.0
#13 0x08048be7 in main (argc=2, argv=0xbfab7144) at gtk19.c:70




---

prabahar



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]