Re: gtk and multithreading

    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:
        pleaseupdategui = 1

and the main thread would do the reverse:

    while 1:
        doupdate = pleaseupdategui
        pleaseupdategui = 0
        if doupdate:

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)

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