Re: Thread programming



On Wed, 2003-06-18 at 06:13, Tristan Van Berkom wrote:
...(snip)...
I was actually waiting for you to ask that question ;-)

    I guess this is your first experience with gtk, gtk programming
generaly
isn't "proceedural" programming in the sence that the main loop
driving your
proceedure  is hidden inside the GMainLoop (in gtk_main()). Generaly
you 
hook
some callbacks to some widgets or timers or file descriptors (all of 
which can
be viewed as "sources"). In my previous pseudo code example; I
sugested
that before you call `gtk_main()' you call `g-io-channel-unix-new()'
on 
a socket
or named pipe and then call `g_io_add_watch()' so you have a GIOFunc
that
will be called every time there is data on the file descriptor (you
can 
have as
many of theese watches as you want; the `select()' or `poll()' call is
hidden
deep in glib.

(this way ofcourse you would feed information through your socket from
the
child thread)

docs:

http://developer.gnome.org/doc/API/2.0/glib/glib-IO-Channels.html#g-io-channel-unix-new

http://developer.gnome.org/doc/API/2.0/glib/glib-IO-Channels.html#g-io-add-watch

BUT!! I think it is to your advantage to use the GAsynchQueue:

http://developer.gnome.org/doc/API/2.0/glib/glib-Asynchronous-Queues.html
(read up and understand)
since this api is made for _exactly_ this purpose, I would prefer it.
(for the purpose of communicating between threads).


Cheers,
                                                -Tristan
I read up on the GAsynchQueue, and it sounds like it would work very
well with the application, and it looks very straight forward to use.

Now all I'm missing is one last thing.  You mentioned the
g_io_add_watch() function for checking the socket for new data.  This
function sounds like it is exactly what I would need, since it "Adds the
GIOChannel into the main event loop with the default priority.". 
However, what hook would I use for the GAsynchQueue to insert a function
in the GMainLoop that would check this queue for new data?  Without
this, I would be stuck again not having a way to get into the GMainLoop,
which come to think of it, has been my main problem all along.

Thanks.  And yes, I only recently started coding with GTK+ and am still
getting used to anything other than procedural programming.  The help I
have received on this list has been great!




_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
-- 
Justin Hopper <gus gusalmighty com>




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