Re: g_thread_init() and gtk_init() segmentation faults



Richard Baverstock wrote:

I'm trying to write a (GTK+2) program with multiple threads using g_thread_init(), but I have yet to figure 
out how without receiving segmentation faults. The following is the snippet of code that invokes 
g_thread_init() and calls gtk_init().

int
main (int argc, char *argv[])
{
 GtkWidget *menu_bar;
 GtkWidget *toolbar;
 GtkWidget *hbox1;
g_thread_init(NULL); gtk_init(&argc, &argv);

 bb_read_options_file ();
 if (options.start_project)
   options.project = options.start_project;

...


and it goes on.

Yes, it's compiled with -lgthread-2.0 and not -lgthread. Well, I actually use pkg-config --libs gthread-2.0, 
which has that.
Using gcc 3.2.2 with posix thread support compiled in.


Currently, with this, I get a segmentation fault at gtk_init(&argc, &argv);. This is the output from gdb:

Starting program: /home/baver/Programming/baverburner/src/baverburner [New Thread 1024 (LWP 29722)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 29722)]
0x08056bc0 in ?? ()
(gdb) bt
#0  0x08056bc0 in ?? ()
#1  0x4004832a in g_main_context_new () at gmain.c:679
#2  0x400483b9 in g_main_context_default () at gmain.c:705
#3  0x400485c9 in g_source_attach (source=0x8068240, context=0x0) at gmain.c:820
#4  0x402e51af in _gdk_events_init (display=0x80657e0) at gdkevents-x11.c:190
#5  0x402dd1dd in gdk_display_open (display_name=0x0) at gdkdisplay-x11.c:217
#6  0x402c1a0d in gdk_display_open_default_libgtk_only () at gdk.c:402
#7  0x4014b16e in gtk_init_check (argc=0xbffff934, argv=0xbffff938) at gtkmain.c:872
#8  0x4014b1aa in gtk_init (argc=0xbffff934, argv=0xbffff938) at gtkmain.c:901
#9  0x0804c48d in main (argc=1, argv=0xbffff994) at main.c:55
#10 0x40444571 in __libc_start_main () from /lib/libc.so.6



I am at a total loss as to what I am doing wrong. I've tried IRC channels, forums, mailing lists archives 
etc. It's bound to be something ironic. Anyways, if anyone can help me figure this out, it will be much 
appreciated.


Rich
aka Baver

You have to use gdk_threads_init() call before gtk_init, but I can't imagine how this can segfault your app in single thread inside gtk_init...
If you post me the code example I'll try to check this...

Olexiy




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