From: Joerg Czeranski <jc@joerch.org>
To: caml-list@inria.fr
Subject: Are exceptions evil? (was: more patches)
Date: Mon, 17 May 1999 13:03:28 +0200 (MET DST) [thread overview]
Message-ID: <5v7vbEfo9$0Ta$1@joerch.org> (raw)
In-Reply-To: <5v6tgd6vv$19X$1@joerch.org>
This morning I rethought my patches under the shower and found another
bug (signals are not blocked while the handler is executed, if the
signal was caught with async_signal_mode == 0).
It's not difficult to fix, I'll do that later. Even the signal
loss race condition can be fixed without too much thought.
But that's because signals are easy to control, they move down the
stack (for stacks growing down). They won't bypass interrupted
functions, they only return to them after being handled.
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".
N.b.: For me acquire is usually Unix.openfile, but it could as well
be a native O'Caml function with sideeffects (like "incr semaphore").
I think the fundamental reason for this problem is that exceptions
are thrown up the stack and not forward on the timeline of side effects.
They ought to skip new acquire calls, but never a release call for
a resource already acquired.
Is there anything that can be done about this? Or does it require
wrapping all (relevant) side effects with monads? Or am I missing
something?
regards,
joerch
next prev parent reply other threads:[~1999-05-17 15:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-05-16 21:40 more patches (for Unix signal mask) Joerg Czeranski
1999-05-17 11:03 ` Joerg Czeranski [this message]
1999-05-18 1:25 ` UPDATE: more patches Joerg Czeranski
1999-05-18 16:10 ` more patches (for Unix signal mask) Xavier Leroy
1999-05-19 18:32 ` 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='5v7vbEfo9$0Ta$1@joerch.org' \
--to=jc@joerch.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