Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@trusted-logic.fr>
To: Joerg Czeranski <jc@joerch.org>
Cc: caml-list@inria.fr
Subject: Re: more patches (for Unix signal mask)
Date: Tue, 18 May 1999 18:10:20 +0200	[thread overview]
Message-ID: <19990518181020.A24993@hoedic.trusted-logic.fr> (raw)
In-Reply-To: <5v6tgd6vv$19X$1@joerch.org>; from Joerg Czeranski on Sun, May 16, 1999 at 11:40:56PM +0200

> I had a look at the web interface to Caml's CVS repository
> and noticed that my previous patches are already incorporated
> (except for byterun/intern.c, but I'm not so sure that it makes
> a difference at all). :-)

I'm still not sure whether the casts are really needed or whether the
Dec C compiler is wrong in emitting a warning.

> I replaced all sigsetjmp() calls with _setjmp() calls (setjmp() is
> allowed to modify the signal mask, too, as per Single Unix Spec v2)
> and handled jumps out of signal handlers separately.

That's an interesting idea; I'll have to think about it.  By the way,
you can just do sigsetjmp(..., 0) if you don't want the signal mask to
be saved and restored; this is more portable than _setjmp.  

> Exceptions on the other hand go straight up the stack until they find
> a handler, and then *immediately* invalidate the handler.
> In a non-pure programming language like O'Caml this creates unavoidable
> race conditions:
> 	let resource = acquire () in
> 	try
> 		use resource;
> 		release resource
> 	with e ->
> 		release resource;
> 		raise e
> "release" is never called if two exceptions arrive at virtually
> the same time, and neither if an exception arrives after the call
> to "acquire", but before the "try".

Yes, asynchronous exceptions (such as those generated from a signal
handler) are very hard to use because of this.  The programming idiom
you showed above is safe for synchronous exceptions (exceptions that
can only be raised by "use resource"), however.

My take on this is that exceptions as they are implemented now are
just fine as a non-local control structure inside a sequential
program, but that something else is needed for multithreaded and
signal-based processing.  The thread cancellation model of Posix threads
is an interesting example of how inter-thread asynchronous
notifications can be made safe.

Regards,

- Xavier Leroy




  parent reply	other threads:[~1999-05-19 17:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-05-16 21:40 Joerg Czeranski
1999-05-17 11:03 ` Are exceptions evil? (was: more patches) Joerg Czeranski
1999-05-18  1:25 ` UPDATE: more patches Joerg Czeranski
1999-05-18 16:10 ` Xavier Leroy [this message]
1999-05-19 18:32   ` more patches (for Unix signal mask) Joerg Czeranski
1999-05-25 15:16     ` John Skaller
1999-05-27 19:10       ` Xavier Leroy

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=19990518181020.A24993@hoedic.trusted-logic.fr \
    --to=xavier.leroy@trusted-logic.fr \
    --cc=caml-list@inria.fr \
    --cc=jc@joerch.org \
    /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