caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Jesper Louis Andersen <jesper.louis.andersen@gmail.com>
Cc: Anders Peter Fugmann <anders@fugmann.net>,
	caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Bug when printing from signal handlers?
Date: Thu, 20 Mar 2014 00:21:36 +0100	[thread overview]
Message-ID: <1395271296.27397.11.camel@zotac> (raw)
In-Reply-To: <CAGrdgiUoPC=Wa6cTkWyuhCSUhFw3D6+igcJ0CT0UEn9nHW1e3A@mail.gmail.com>

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

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.

Gerd

Am Mittwoch, den 19.03.2014, 23:19 +0100 schrieb Jesper Louis Andersen:
> 
> On Wed, Mar 19, 2014 at 10:21 PM, Anders Peter Fugmann
> <anders@fugmann.net> wrote:
>         Is printing from a signal handler illegal?
> 
> FWIW, that is illegal in some operating systems. I have seen it in one
> case at least:
> 
> 
> * Linux with threads. printf in C is protected by a mutex. Suppose we
> are inside the printf, with the mutex locked and then we get a signal.
> We run the handler, and it wants to print out debug information.
> Welcome deadlock!
> * Many system calls are not safe in the signal handler. FreeBSD has a
> list in sigaction(2) for instance. See
> 
> 
> 
>  http://www.freebsd.org/cgi/man.cgi?query=sigaction&apropos=0&sektion=0&manpath=FreeBSD+10.0-RELEASE&arch=default&format=html
> 
> 
> In practice, you should probably just set a flag in the signal handler
> and then handle that in a main loop of the program. Doing advanced
> stuff in a signal handler is usually dangerous non-compatible
> territory.
> 
> 
> 
> -- 
> J.

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

  reply	other threads:[~2014-03-19 23:21 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 [this message]
2014-03-20  5:29     ` ygrek
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=1395271296.27397.11.camel@zotac \
    --to=info@gerd-stolpmann.de \
    --cc=anders@fugmann.net \
    --cc=caml-list@inria.fr \
    --cc=jesper.louis.andersen@gmail.com \
    /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).