Re: [gtk-list] Re: thread safe gtk?



Some reference has been made to Win32 being thread safe.  Being the Win32 guru
that I am (I'm not proud of this, thank you), let me describe how Win32's GUI
and multiple threads interact.

First, a disclaimer:  I am not impressed by Win32's GUI-threading model, and am
not suggesting adapting this model.  It still contains plenty of Windows 2.0
baggage (ick) which we would certainly be better off not to emulate.

1) Win32 has two types of threads: "User-interface" threads and "Worker"
threads.
2) User-interface threads are worker threads that provide a message queue.  The
way MS refers to them, they most likely have UI code in the threading code,
which I wouldn't put past them.
3) The application may explicitly provide a message queue using GetMessage(),
DispatchMessage() and optionally TranslateMessage() (if you have accelerator
tables).  There are other methods for providing a message queue, but they have
really long API names which I can't remember.
4) Showing a modal dialog box automatically provides the message-queue.
(Speaking of which, I'd like to see a gtk_widget_show_modal () which does the
same thing...  Before someone flames me for liking modal dialogs, I frankly
don't like dialogs at all: I like to make everything dockable.
gtk_widget_show_modal() could be a replacement for gtk_main() though. )
5) Messages to windows (events/signals in GTK terms) are dispatched via the
windowing kernel, and are queued on the appropriate thread.  The windowing
kernel will even marshal message data accross process boundaries, although this
would provide much bulk to GTK, and there are simpler, more effective ways of
handling this for apps which may need to.
6) Direct access to a window from another thread is allowed, because only one
thread is allowed to draw to a window at a time (via BeginPaint() and
EndPaint() or GetWindowDC() and ReleaseDC().).  Windows stores an invalid
region, which BeginPaint() and EndPaint() are allowed to access.
(GetWindowDC() and ReleaseDC() can paint anywhere on the window).  Windows can
therefore allow two different programs to access different areas of the screen
simultaneously if they don't have overlapping invalidated regions.

Use this information wisely, young Jedi.

-Jay



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