Re: [gtk-list] gtk and pthreads?



On Fri, 26 Jun 1998, Joe Pfeiffer wrote:

> Has anybody here used gtk with pthreads?  If so, I'm curious as to
> exactly what it took to get them to cooperate (yes, I've read the
> FAQ.  My experiment blew up before I ever cloned a thread...).

Currently GTK isn't thread-safe, but you *can* use threads and GTK
concurrently.  You need to watch what you're doing however.  :)

For effective GTK-thread programming, you want to keep all GTK calls to
one (main) thread.  If the other thread needs to draw something, have it
communicate with the original thread via some thread-safe mechanism, like
a queue.

What I did was have my secondary thread (the one that did the actual work)
write to a thread-safe queue (I defined my own class in C++ to do this,
wrapping all internal code in mutex locking and unlocking code).  The main
thread, the one with GTK in it, would in turn read this thread and do the
appropriate predefined action (in my case, write a pixel to the screen),
via a timer function.

Another way to use threads and GTK is to use GPK (General Proxy Kit).
This is a thread-based wrapper around GTK, and the last time I checked it
wasn't totally complete and I don't even know if it's even up-to-date
anymore, but it may suit your purposes (if it works).

http://www.humanfactor.com/gpk/

I'd like to put a disclaimer:  I'm just learning this, so take my advice
with a grain of salt.  =D  I'd particularly like to hear feedback on this,
too.

Hope this helps!

                                      - Dave

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  Name:  David Finton                  | "All free software is in Beta.  If
 Email:  dfinton@d.umn.edu             |  there is a free software package
   Web:  http://www.d.umn.edu/~dfinton |  bearing the version number 1.0 or
                                       |  greater, it is obsolete and must
                                       |  be replaced immediately by a
                                       |  newer, better Beta version."
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-





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