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.

Usually you may want two threads, one for the UI and another to receive
commands and data.

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??

"Forking" is not "threading".  

When you fork, you're creating an independent process, with different
address space and without communication capabilities out of the system's
IPC mechanisms. Threads use to live on the same process and use to share
memory and resources - depending on the implementation. 

http://en.wikipedia.org/wiki/Fork_%28operating_system%29
http://en.wikipedia.org/wiki/Thread_%28computer_science%29

Here you've got an example of fork() in GTK+
http://www.mhatt.aps.anl.gov/dohn/programming/gtk-2.0/gtk-faq/x506.html

ITOH you may take a look at GThread implementation.
http://developer.gnome.org/doc/API/2.0/glib/glib-Threads.html

Said that, it's much better not to start programming complex network
based multi-threaded applications unless you've got some programming
background on single-threaded environments, and you know quite well the
toolkit/system you're using. 
-- 
Iago Rubio




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