Re: [AD] [Unix] Using pthreads |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Fri, Apr 13, 2001 at 02:56:28PM +0700, Michael Bukin wrote:
> Just a little comment, I have not looked into your code, so maybe this
> comment is wrong.
No, it's dead right. :)
> There is one more type of "threading", when critical signal hooked by
> Allegro is caught (e.g. SIGINT). Will this new locking work in this
> case, or it may hang in deadlock (when allegro_exit shuts down gfx
> driver), or call nested Xlib function?
Yes, I forgot to mention it -- I didn't handle that case neatly.
When signals are raised at bad times, it will currently
deadlock. In testing, I disabled all the signal hooking (I'm
not sure whether we actually need this in the X version since we
don't really do anything dangerous, do we?). When the signals
are hooked and one is raised between a XLOCK()...XUNLOCK() pair,
using either pthreads or sigalrm, the XLOCK() which is invoked
from the signal handler will deadlock. It's possible to detect
when this will happen in the sigalrm case (as you did before),
but we can't tell when it will happen using proper X display
locking -- there's no way to poll, you can only wait until it
gets unlocked.
I'm not sure what to do about it at the moment, but there must
be something. We can track our own usage through the
XLOCK/XUNLOCK macros, and skip the shutdown if the display is
already in use. But if the user calls Xlib functions, and there
is a crash between their XLockDisplay/XUnlockDisplay calls, we
will get a deadlock.
Ah, actually, that will only happen if the user calls these from
a created thread -- if they do it in the main thread then it's
just nesting, which is fine. But there is still the problem of
interrupting an in-progress X function.
AFAICS tidying up on exit isn't essential -- the X server will
close our window when we close the display connection, i.e. when
we terminate. If we've changed the video mode, we can still
change it back by opening a new display connection to do that.
I'm not sure, though, about DGA; I think this has exclusive use
of the display, so maybe that's a problem if the program just
vanishes? I think the X server really ought to handle this case
neatly too though.
George
--
Random project update:
22/06/2000: AllegroGL documentation: http://allegrogl.sourceforge.net/
See under `Documentation' for the AllegroGL Reference Manual in
various formats.