Re: thread problem

Peter Montgomery <[email protected]>
Newsgroups gmane.comp.video.gimp.windows.devel
Message-ID <[email protected]>
drhammerit,

> drhammerit writes:
>  > my program use two thread, one stay in gtk_main() and the other
>  > receive data from the net and draw somo control on the main window.
>
> Won't work. GTK+ on Windows does not work in general when used from
> multiple threads. This is something that needs to be fixed. The fix,
> AFAIK, would be to use a single thread (internally in GDK) for all GDI
> interaction. I.e. it will require quite a lot of internal
> restructuring and recoding.
>
> If you can restructure your program yourself so that all GTK+ calls
> that will invoke GDI are done from a single "GUI" thread, it should
> work fine. (Note that any thread can invoke "callbacks" in the GUI
> thread using gtk_idle_add.)

I just wanted to add that this is the norm under Windows.  If you have a
multi-threaded application, it's important that only one thread is
responsible for updating the GUI, or else bad things happen.  In a
Windows only program, you can use a function called
RegisterWindowsMessage( ) to get Windows to create a custom message
number for your custom messages.  Using those, you can then post custom
messages from the worker thread to the main thread to tell it things
such as the GUI needs updating.  In this way, your BG thread works and
posts messages while your main thread "owns" and is responsible for
updating the GUI.  I have to confess I'm not sure what the exact
equivalent would be to duplicating this scenario using GDK.  Perhaps Tor
or someone else can chime in?

    Thanks,
    PeterM
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.