Help: multithreaded GNOME app



I'm writing a gnome app that uses threads.  I am assuming gtk+ and gnome-libs
aren't thread safe (unless the FAQ is out-of-date).  So what I want to do
is have one thread handle all gtk+ calls -- this seems to be the easiest
approach.

So gtk_main() will be run by thread A, and thread A will be responsible for all
GUI calls.  So if thread B comes along and needs to make a gtk call, it can put
this on some sort of queue.  Thread A will monitor this queue and handle the
request.  Seems simple enough.  But the problem is, how will it monitor this
queue?  Using a timer call seems a really bad way to do this, since there can
be at most x time elapsed between the request and the action, where x is the
amount of time between checking the queue.  And x obviously can't be 0, 
because then thread A would be in a busy wait.

I was thinking of using a file handle as the sort of communication-between-
threads mechanism that I need to do.  Thread A can monitor some file handle
fd.  When fd has data, it knows there is a request to do a draw, and this
will happen immediately.  But I'm asking if there is a more elegant way
to do this?  Maybe some thread message passing functions?

Thanks in advance,
Jason.



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