Hello,
What if the GSourceFunc blocks for a longer time, eg. for 3 seconds time.
Does it freeze the GUI because it runs within the main-loop?

One possible approach:
My audio-recorder uses a message queue (g_async_queue_new()) to receive
data from various modules and threads.
Ref:
http://bazaar.launchpad.net/~osmoma/audio-recorder/trunk/view/head:/src/rec-manager.c
(notice: this solution is too slow to update a progressbar or levelbar may
times a second).

This message queue is checked continuously by a thread which then updates
the GUI, starts/stops/pauses recording etc.
See the rec_manager_init() function.

Various parts of the program can send messages to the GUI/app by calling:

void rec_manager_send_command(RecorderCommand *cmd) {
    // Push command to the queue
    g_async_queue_push(g_cmd_queue, (gpointer)cmd);
}

void rec_manager_init() {
    LOG_DEBUG("Init rec-manager.c.\n");

    // Create a message queue
    // Ref: http://www.gtk.org/api/2.6/glib/glib-Asynchronous-Queues.html
    g_cmd_queue = g_async_queue_new();

    // Message thread within GTK's main loop
    // Ref: http://developer.gnome.org/glib/2.31/glib-The-Main-Event-Loop.html
    g_thread_id =  g_timeout_add_full(G_PRIORITY_DEFAULT, 200,
rec_manager_command_thread, NULL, NULL);

    // Init recorder.c
    rec_module_init();
}

Audio-recorder
https://launchpad.net/audio-recorder

Kindly
  Moma Antero


On Wed, Oct 24, 2012 at 4:34 AM, Ardhan Madras <ard...@rocksis.net> wrote:
>
> Hi,
>
> >     Now that from GTK+ 3.6, thread functions are deprecated.  Is there
any
> > new rules to do threading with the gtk+ 3.6 version?
>
> Are you talking about Glib? yes, there are many changes since 2.32
> (for now stable version is 2.34), from high level view, the changes
> such as new thread creation functions, thread reference counting
> functions, thread synchronization tools, etc. and many other functions
> and macros has been removed.
>
> In 2.32 and above to create a thread you will use the new
> g_thread_new() or the g_thread_try_new() (previously with
> g_thread_create()), to create synchronization tools for example a
> rwlock then you call g_rwlock_init (previously g_rwlock_new() or
> G_STATIC_RWLOCK_INIT), call g_thread_unref() after you finish with the
> thread.
>
> >     I tried */g_main_context_invoke/*, but seems it did not work. I
can't
> > update GUI from that GSourceFunc. Maybe is my mistaken use...
>
> I don't understand why you call g_main_context_invoke() here but If
> you want to call GTK+ functions from your thread, the safe method is
> to wrap the functions to a GSourceFunc and call it with g_idle_add()
> or g_idle_add_full() (from your thread function).
>
> Regards.
>
>
> On Tue, Oct 23, 2012 at 9:43 AM, Weitian Leung <just_fa...@live.com>
wrote:
> > Hi,
> >     Now that from GTK+ 3.6, thread functions are deprecated.  Is there
any
> > new rules to do threading with the gtk+ 3.6 version?
> >     Just for an example, I want to download many files in background,
and
> > show the progress in GUI, how should I do it?
> >     I tried */g_main_context_invoke/*, but seems it did not work. I
can't
> > update GUI from that GSourceFunc. Maybe is my mistaken use...
> >     Anyone know how? Or just give me some examples.
> >
> >     Sorry for my bad English.
> >     Thanks.
> >
> > --
> > Weitian
> >
> > _______________________________________________
> > gtk-app-devel-list mailing list
> > gtk-app-devel-list@gnome.org
> > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
>
>
> --
> Please do not send me any propriety format such as Microsoft Offices:
> Word, Excel, Power Point, etc. Please use standard non-propriety
> format such as plain text, HTML, PDF or OpenOffices format.
>
> ROCKSIS | Indonesia
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to