caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: ygrek <ygrek@autistici.org>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Bug when printing from signal handlers?
Date: Thu, 20 Mar 2014 13:29:41 +0800	[thread overview]
Message-ID: <20140320132941.09aa04f4@kiwi.local.tld> (raw)
In-Reply-To: <1395271296.27397.11.camel@zotac>

[-- Attachment #1: Type: text/plain, Size: 1294 bytes --]

On Thu, 20 Mar 2014 00:21:36 +0100
Gerd Stolpmann <info@gerd-stolpmann.de> wrote:

> OCaml printing isn't printf in C - it calls directly write() and is
> always possible. OCaml signal handlers aren't signal handlers from the C
> viewpoint: When the signal is caught, a flag in the OCaml runtime is
> set, and this flag is regularly checked by the running code. (I.e. what
> you suggest is already done in the runtime.)
> 
> So, I'd say this is a bug in the OCaml runtime. The bug goes away when
> you print to a different channel from the signal handler, so it looks
> like channels and signal handlers have some unwanted effect on each
> other.

stdlib channels are protected with non-recursive mutex, so the deadlock on re-entrant invocation is guaranteed. 
AFAICS runtime system tries to execute signal immediately (see signal_handle in asmrun/signals_asm.c)
and if that is not possible - records signal for later execution.
Anyway doing complex stuff in signal handler is a bad idea, because even with delayed processing (when
things are safe from the libc point of view) the points of invocation of OCaml signal handler are scattered
all around the program (allocation sites) and any OCaml resource that doesn't support reentrant usage will break
the program.

-- 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2014-03-20  5:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-19 21:21 Anders Peter Fugmann
2014-03-19 22:19 ` Jesper Louis Andersen
2014-03-19 23:21   ` Gerd Stolpmann
2014-03-20  5:29     ` ygrek [this message]
2014-03-20  7:42       ` Anders Fugmann
2014-03-20 20:07       ` Gerd Stolpmann
2014-03-23 10:01         ` ygrek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140320132941.09aa04f4@kiwi.local.tld \
    --to=ygrek@autistici.org \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).