Re: Multi-threading & portability



On Wed, Oct 02, 2002 at 02:30:22PM +0300, Olexiy Avramchenko wrote:
> Jean-Yves Lefort wrote:
> 
> >Hi all,
> >
> >Please consider the attached C source.
> >
> >It runs fine on FreeBSD, but freezes on Linux. gtk_dialog_run() calls
> >a recursive main loop, but I don't know how to interpret this fact to
> >solve my problem. The workaround I use actually is to simply remove
> >the gdk_threads_enter()/gdk_threads_leave() pair wrapping the main
> >loop, as the program runs fine without them.
> >
> >Why should I wrap the main loop with that pair?
> >Is the attached program not correct? Did I mess up somewhere?

[...]

> >  g_signal_connect(G_OBJECT(window), "delete_event",
> >		   G_CALLBACK(delete_event_handler), NULL);
> >
> You can save some lines of code here, if you put: g_signal_connect(..., 
> (GCallback)gtk_main_quit, ...) ;)

Oh no, this is kludgy programming ;)

[...]

> >  dialog = gtk_message_dialog_new(GTK_WINDOW(window),
> >				  GTK_DIALOG_DESTROY_WITH_PARENT,
> >				  GTK_MESSAGE_WARNING,
> >				  GTK_BUTTONS_OK,
> >				  "Test dialog");
> >
> /* You need to put these lines to get it work under Linux: */
> gdk_threads_enter(); /* you owns the mutex, this line can be ignored */
> 
> > gtk_dialog_run(GTK_DIALOG(dialog));
> >
> gdk_threads_leave();    /* you freeing the mutex, this line is what you 
> need */

Yes, it works correctly if I take care of not locking a mutex
recursively inside the same thread; thank you very much for your time.

Regards,
Jean-Yves Lefort

-- 
Jean-Yves Lefort

jylefort brutele be
http://void.adminz.be/

Attachment: pgpazs06ccqHH.pgp
Description: PGP signature



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