Re: A problem about programming with Gtk+



that bit of documentation is a bit confusing and definitely misleading. 
what it essentially says is that if you make calls to gtk_ or gdk_ then
the thread calls are required.

but if all calls to gtk_ and gdk_ are executed within routines executing
as part of the main loop, thread calls are not required.

g_idle_add() is guaranteed to be thread-safe without calling
g_thread_init() or gdk_threads_init().

since Result() is executed via g_idle_add(), it is executed under the main
loop.  therefor, no calls to gtk_threads...() are necessary here.

richard


On Sat, Dec 27, 2008 at 3:42 AM, Vyacheslav D. <bordimida mail ru> wrote:

    On Tue, 23 Dec 2008 04:42:09 +0300, haitao_yang foxitsoftware com
<haitao_yang foxitsoftware com> wrote:

    From gnome help:

    "Idles, timeouts, and input functions from GLib, such as g_idle_add(),
are executed outside of the main GTK+ lock. So, if you need to call
GTK+ inside of such a callback, you must surround the callback with a
gdk_threads_enter()/gdk_threads_leave() pair or use
gdk_threads_add_idle_full() which does this for you"

    Proof link: http://library.gnome.org/devel/gdk/stable/gdk-Threads.html

    So i think you should try so:


    static gboolean Result (gpointer data)
    {
           gint param = (gint)data;
           gdk_threads_enter();

           GtkWidget* pDialog = gtk_message_dialog_new(GTK_WINDOW(win),
                   GTK_DIALOG_MODAL,
                   GTK_MESSAGE_INFO,
                   GTK_BUTTONS_OK,
                   "The thread result: %d ",
                   param);
           gtk_dialog_run(GTK_DIALOG(pDialog));
           gtk_widget_destroy(pDialog);
           gdk_threads_leave();
           return FALSE;
    }

    --
    Vyacheslav D.





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