Re: GTK and threaded applications



kornelix wrote:
Following the guidelines in the FAQ, I constructed my application threads as follows:

  gdk_threads_enter();                //  enter thread
       (do some work, including GTK calls)
  gdk_flush();                            //  exit thread
  gdk_threads_leave();   return 0;

Now my multi-threaded application executes its threads one after the other, instead of in parallel. Apparently the above method introduces a lock or mutex which allows only one thread at a time to execute.

Is this a hopeless situation, or is there some other way?
(other than putting all GTK calls in the main program)

IMO,
     overall you'll have a cleaner program design if you put
all your GUI interaction in the main thread.

Now if I'm reading you right; what your experiencing is normal,
calling gdk_threads_enter/leave is locking a global mutex for
GTK/GDK interaction.

The rule is, you cant have two threads access the GTK+ api
at once, so:
     o You can have a multithreaded application using GTK+
     o You can even go to the extreme of calling GTK+ functions
       from seperate threads, but you must take care to lock
       GTK+ down with gdk_threads_enter/leave()
     o You *cant* call GTK+ functions from more than one thread
       and expect GTK+ to execute simultainiously.

Cheers,
                         -Tristan




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