Re: thread-safe "pixmap-server"
- From: Havoc Pennington <hp redhat com>
- To: "Tony K." <tony kwok 3web net>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: thread-safe "pixmap-server"
- Date: 05 Sep 2001 13:34:27 -0400
"Tony K." <tony kwok 3web net> writes:
Now the GTK+ FAQ (5.2) states that GLib is not
thread safe, and must be initialized with g_thread_init(),
and the gtk_main() must be sandwiched between
gdk_threads_enter() and ...leave(). This, as far as I
understand, means that all calls to GLib functions
are internally locked to execute one at a time.
GLib calls are not, GLib is threadsafe. However, GDK/GTK+ have a
global lock that must be held in order to do GUI stuff.
Given all this, is it reasonable to expect that multiple
images which require lots of computation, i/o and gdk
(but not gtk) calls would be created in parallel?
GDK calls run one at a time, due to the global lock. However, you can
do locking at whatever granularity you like; i.e. you can lock over
300 GDK calls, which will block other threads for 300 calls, or you
can lock over each GDK call, which will let the threads interleave.
Of course, while not using GDK you should avoid holding the GDK global
lock, so that other threads can use GDK.
It's hard to know how much time your threads will spend waiting for
the GDK lock; you'd have to profile it. Or maybe you can predict in
advance how much time the threads will spend in computation and how
much in drawing.
In general, you will not want to make many GDK calls and they'll be
fast. That is, if you're using gdk_draw_point() very often, it's going
to be horribly slow, and what you probably should do instead is render
on the client side to an RGB buffer, and then make a single GDK call
(gdk_draw_rgb_image). Guppi is a good example of an application that
does this and has very fast plotting abilities. You could do the RGB
buffer drawing in a threadsafe way and avoid needing a lock for that.
Or should
the pixmap-server function use some other graphical
library which is thread safe. Is there such a thing?
I believe Motif works similarly to GTK, except that it manipulates the
global lock internally (all functions contain a lock()/unlock() pair
internally). Could be wrong about this. Anyhow, this would have the
same performance characteristics as GTK, but would involve less
typing. Of course Motif requires more typing in other areas.
Swing/WinForms I think have an explicit lock for each toplevel
window. So it's like GTK (do your own locking) but you get a separate
lock for each window, instead of a global lock. I could be wrong about
that too but this is what I'm told.
Another thing you may be able to do is use plain Xlib for the drawing
code; it's not that different from GDK. However I don't know of any
reports of people trying this. You would need to call XInitThreads()
also.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]