Re: threads & gtk



On Sat, 2006-08-05 at 18:22 +0200, chabayo wrote:
Hello, i'll ask for help with gtk & threading.


The rules of my template:

Create an output Window.
Listen on a Socket for commands.
Listen on a Socket for data.


I wanna have 3 threads - naturally.

This kind of situation lends itself very well to asynchronous IO.  In
fact, it's likely better than threading as there are less chances for
race conditions and everything is event-driven, which fits into the gtk
paradigm.  You'll want to look into the g_io_channel calls for watching
descriptors.  You can then turn commands and data into normal events.
Alternatively check out the gnet library.   If the data processing takes
too long to be handled in a purely asynchronous manner, spawn a thread
just at that point.

Yes three threads should work for you.  The main thread can run the gui
and then spawn some gthreads for the socket workers.  As has been said,
fork will not work in this case, unless you want to use something else
for IPC like signals and shared memory.


Therefor i built that scheme:

main () {
...
   /* init threads */  
   g_thread_init(NULL);
   gdk_threads_init();
...
   if ( ! pid ) {
     pid_t pid=fork ();
     gdk_threads_enter ();
     ...
     gdk_threads_leave ();
     exit ( 0 ); }
   else {
     pid_t pid=fork ();
     gdk_threads_enter ();
     ...
     gdk_threads_leave ();
     exit ( 0 ); }
}

...somebody will help me that to trick??


nynhjan

      

      
              
___________________________________________________________ 
Der frhe Vogel fngt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



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