Re: gtk and multithreading



Well unfortunately, the main process is passed to the gtk_main()
function
which, I suppose I could rewrite the gtk_main() function, but it is what
the GTK toolkit gives and recommends using for the main loop.  (the
gtk_main() is built with the GTK libraries)

Anyhow, I could easily do what you suggest if it was a loop I was
directly
controlling....so obviously I need to emit some sort of signal, or
another
suggestion was to have a timer event...but neither of which I know how
to
do...and for my purposes don't seem to be documented very well..  

Skip Montanaro wrote:
> 
>     Brad> Hmm.  How did you "set flags" for the main thread to act upon it?
>     Brad> Did you have to emit some sort of signal?  when running gtk_main()
>     Brad> the only way to interact with it seems to be with signals or
>     Brad> events...
> 
> Well, in Python (the only place I've ever tried to use threads), common
> practice is to guard some shared variable with a lock.  Worker threads that
> want to tickle the main thread into doing something would execute
> 
>     while 1:
>         worksomemore()
>         lock.acquire()
>         pleaseupdategui = 1
>         lock.release()
> 
> and the main thread would do the reverse:
> 
>     while 1:
>         lock.acquire()
>         doupdate = pleaseupdategui
>         pleaseupdategui = 0
>         lock.release()
>         if doupdate:
>             updatethegui()
>         else:
>             time.sleep(0.1)
> 
> or something similar.  I'm just typing a simple example.  I'd probably
> actually use a different structure in actual code to avoid having explicit
> sleeps in my code.  Lock is some sort of mutex.  I assume the threading
> stuff in GDK provides similar capabilities, though I've never looked at it.
> 
> --
> Skip Montanaro (skip pobox com)
> http://www.mojam.com/
> http://www.musi-cal.com/

-- 
-----------------------------
Brad House
Sr. Developer
Main Street Softworks, Inc.

brad mainstreetsoftworks com
(352) 378-8228
-----------------------------




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