[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: a little puzzle
From: |
Andy Wingo |
Subject: |
Re: a little puzzle |
Date: |
Sun, 10 Oct 2010 16:58:04 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
On Fri 08 Oct 2010 19:32, Andy Wingo <address@hidden> writes:
> On Fri 08 Oct 2010 19:14, Andy Wingo <address@hidden> writes:
>
>> That's right: two throws for the price of one! The interrupted syscall,
>> and then the asynchronous signal. Fun...
>
> I propose to fix it with a patch like this:
>
> --- a/libguile/error.c
> +++ b/libguile/error.c
> @@ -147,6 +147,7 @@ void
> scm_syserror (const char *subr)
> {
> SCM err = scm_from_int (SCM_I_ERRNO ());
> + SCM_ASYNC_TICK;
> scm_error (scm_system_error_key,
> subr,
> "~A",
I did so, wrapping in #ifdef EINTR, and with the additional comment:
/* It could be that we're getting here because the syscall was
interrupted by a signal. In that case a signal handler might have
been queued to run. The signal handler probably throws an
exception.
If we don't try to run the signal handler now, it will run later,
which would result in two exceptions being thrown: this syserror,
and then at some later time the exception thrown by the async
signal handler.
The problem is that we don't know if handling the signal caused an
async to be queued. By this time scmsigs.c:take_signal will have
written a byte on the fd, but we don't know if the signal-handling
thread has read it off and queued an async.
Ideally we need some API like scm_i_ensure_signals_delivered() to
catch up signal delivery. Barring that, we just cross our digits
and pray; it could be that we handle the signal in time, and just
throw once, or it could be that we miss the deadline and throw
twice.
*/
#ifdef EINTR
if (scm_to_int (err) == EINTR)
SCM_ASYNC_TICK;
#endif
--
http://wingolog.org/