Re: Help: multithreaded GNOME app



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

You could use semaphores (I would suggest you get the book Unix Network
Programming by Stevens) to monitor the queue.  This is method is generally
used in operating systems when working with many processes.

[I'm assuming you don't know what a semaphore here, if you do just ignore
the rest of this message]

A semaphore could be an integer variable that shifts values between 0 and
1.  If it's 0 someone is using a gtk call, the process that is using the
gtk call can return, and then set the semaphore to 1 which indicates that
the thread is done and whatever process blocking on the semaphore is free
to make the call.  semaphores are supported in Linux check out "man -k
semaphore"

There are some dangers to this, so you'll have to make sure that no
process blocks indefinitely on the semaphore for whatever situation.  It
might slow down the application as well...

I'm sure if I've made a mistake here in my explaination, someone will
correct me.

	sri

---------------------------------------------------------------------------
Sri Ramkrishna         /|\ Unix is very user friendly, its just very picky
email: sri@aracnet.com -|- on who it is friendly to. -- Unknown? 
phone: 503-356-1078    \|/ 
---------------------------------------------------------------------------
                        |





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