Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: "Daniel Bünzli" <daniel.buenzli@epfl.ch>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Has the thread cancellation problem evolved ?
Date: Tue, 28 Aug 2007 13:42:51 +0200	[thread overview]
Message-ID: <1188301371.7533.48.camel@localhost.localdomain> (raw)
In-Reply-To: <BF8C1117-83A3-46AA-82C4-EC9D96E51F69@epfl.ch>

Am Dienstag, den 28.08.2007, 11:26 +0200 schrieb Daniel Bünzli:
> Le 28 août 07 à 01:33, Gerd Stolpmann a écrit :
> 
> > Nevertheless, I don't think this is a good thing. Raising an exception
> > at potentially any moment is a problematic thing. E.g. code like
> >
> > let x = try Some(List.assoc ... with _) -> None
> >
> > where the author implicitly assumes that it is only Not_found that can
> > happen and the code is just plain wrong if anything else is encoded  
> > into
> > the exception.
> 
> But this is sloppy programming anyway. The author is plain wrong in  
> assuming that only Not_found can be raised, he is asking for a  
> potential time consuming debugging session.
> 
> 1) If x is polymorphic then List.assoc may raise Invalid_argument  
> (because of compare).
> 
> 2) If the computation of x is embedded in a larger computation the  
> call to List.assoc may raise Stack_overflow.
> 
> 3) The allocation of the block for Some may raise Out_of_memory.
> 
> 4) If we are in the toplevel Sys.Break may be raised.
> 
> IMHO the only place where a catch all handler is allowed is in a  
> toplevel main loop (or a function monitoring other computations).

Of course, my example is a bit simplistic. My point is that it is anyway
difficult to get exception handling right in larger programs, and that
overloading this mechanism with another feature is questionable. We have
generally two kinds of exceptions: programmatic use to pass unusual
result values back, or to exit some recursion (like Not_found), and
those for runtime conditions/limitations (like Out_of_memory) (and some
exceptions are in between). Handling the second type is difficult, as
the program is probably already in a weird state when you try to handle
the condition.

Stopping threads is simple as long as if you only think of computations:
yes, you can stop any computation by raising an exception. But I don't
see a good way to stop I/O operations. Simply close all file
descriptors? Yes, possible, but you may leave files in an unrecoverable
state. It can even have very unwanted effects. Imagine you release locks
at this moment - this may trigger other processes doing something.

I see your problem, but there is no general solution. A thread of
execution is always part of a larger system, and you cannot stop a
system by stopping a thread. The word "stop" has simply no meaning in
this larger context.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------


  reply	other threads:[~2007-08-28 11:42 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-25 13:58 Daniel Bünzli
2007-08-25 15:29 ` [Caml-list] " skaller
2007-08-26 23:47   ` Daniel Bünzli
2007-08-27  0:18     ` Till Varoquaux
2007-08-27  4:38     ` skaller
2007-08-27 10:12       ` Daniel Bünzli
2007-08-27 11:28         ` skaller
2007-08-27 11:49           ` Jon Harrop
2007-08-27 12:24           ` Daniel Bünzli
2007-08-27 12:38             ` Jon Harrop
2007-08-27 13:09               ` Daniel Bünzli
2007-08-27 14:27               ` skaller
2007-08-27  7:55     ` Markus E L
2007-08-27 23:33   ` Gerd Stolpmann
2007-08-28  9:26     ` Daniel Bünzli
2007-08-28 11:42       ` Gerd Stolpmann [this message]
2007-08-28 14:46         ` Daniel Bünzli
2007-08-28 14:23       ` Gordon Henriksen
2007-08-28 14:35         ` Brian Hurt
2007-08-28 14:44           ` Daniel Bünzli
2007-08-28 14:54           ` Robert Fischer
2007-08-28 15:12             ` Brian Hurt
2007-08-28 15:32               ` Gordon Henriksen
2007-08-28 15:40               ` skaller
2007-08-29  8:12               ` Lionel Elie Mamane
2007-08-28 15:00           ` Gordon Henriksen
2007-08-25 15:44 ` skaller
2007-08-26 23:24   ` Alain Frisch
2007-08-25 15:57 ` Gordon Henriksen

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=1188301371.7533.48.camel@localhost.localdomain \
    --to=info@gerd-stolpmann.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=daniel.buenzli@epfl.ch \
    /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